mirror of
https://github.com/apple/swift.git
synced 2026-10-06 12:37:28 +02:00
If we don't require that experimental feature to be enabled, users might accidentally publish swiftinterface files using the attribute, without telling compilers that in order to consume the swiftinterface file, they need UnderscoreOwned enabled. It's a valuable thing to make an error as people may be publishing interfaces that are hiding the computed property always. resolves rdar://174880934
48 lines
1.5 KiB
Swift
48 lines
1.5 KiB
Swift
// RUN: %target-typecheck-verify-swift -target %target-swift-5.1-abi-triple
|
|
// REQUIRES: objc_interop
|
|
// REQUIRES: concurrency
|
|
|
|
import Foundation
|
|
|
|
@_borrowed // expected-error {{'@_borrowed' attribute cannot be applied to this declaration}}
|
|
func foo() -> String {}
|
|
|
|
@_borrowed
|
|
var string = ""
|
|
|
|
@objc protocol P {
|
|
@_borrowed // expected-error {{property cannot be '@_borrowed' if it is an '@objc' protocol requirement}}
|
|
var title: String { get }
|
|
}
|
|
|
|
@objc class A {
|
|
@_borrowed // expected-error {{property cannot be '@_borrowed' if it is '@objc dynamic'}}
|
|
@objc dynamic var title: String { return "" }
|
|
}
|
|
|
|
public class Holder {
|
|
@_borrowed var one: String {
|
|
get async { "" } // expected-error {{getter cannot be '@_borrowed' if it is 'async' or 'throws'}}
|
|
}
|
|
@_borrowed var two: String {
|
|
get throws { "" } // expected-error {{getter cannot be '@_borrowed' if it is 'async' or 'throws'}}
|
|
}
|
|
|
|
// expected-error@+1 {{'@_owned' is an experimental feature; use '-enable-experimental-feature UnderscoreOwned'}}
|
|
@_borrowed @_owned var three: String { // expected-error {{property cannot be '@_borrowed' and '@_owned' at the same time}}
|
|
get { "" }
|
|
}
|
|
// expected-error@+1 {{'@_owned' is an experimental feature; use '-enable-experimental-feature UnderscoreOwned'}}
|
|
@_owned var four: String { // expected-error {{property must define a 'get' to support '@_owned'}}
|
|
_read {
|
|
let x = ""
|
|
yield x
|
|
}
|
|
}
|
|
}
|
|
|
|
#if hasAttribute(_owned)
|
|
#else
|
|
#error("hasAttribute should be true!")
|
|
#endif
|