1
1
// RUN: %target-typecheck-verify-swift -enable-experimental-feature NoncopyableGenerics
2
2
3
- // XFAIL: noncopyable_generics
4
-
5
- // REQUIRES: noncopyable_generics
6
-
7
3
// a concrete move-only type
8
4
struct MO: ~ Copyable {
9
5
var x : Int ?
@@ -71,8 +67,8 @@ takeGeneric(globalMO) // expected-error {{noncopyable type 'MO' cannot be substi
71
67
72
68
73
69
func testAny( ) {
74
- let _: Any = MO ( ) // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any '}}
75
- takeAny ( MO ( ) ) // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any '}}
70
+ let _: Any = MO ( ) // expected-error {{value of type 'MO' does not conform to specified type 'Copyable '}}
71
+ takeAny ( MO ( ) ) // expected-error {{argument type 'MO' does not conform to expected type 'Copyable '}}
76
72
}
77
73
78
74
func testBasic( _ mo: borrowing MO ) {
@@ -83,22 +79,22 @@ func testBasic(_ mo: borrowing MO) {
83
79
takeGeneric ( MO ( ) ) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'takeGeneric'}}
84
80
takeGeneric ( mo) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'takeGeneric'}}
85
81
86
- takeAny ( mo) // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any '}}
87
- print ( mo) // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any '}}
82
+ takeAny ( mo) // expected-error {{argument type 'MO' does not conform to expected type 'Copyable '}}
83
+ print ( mo) // expected-error {{argument type 'MO' does not conform to expected type 'Copyable '}}
88
84
89
85
takeGeneric { ( ) -> Int ? in mo. x }
90
86
genericVarArg ( 5 )
91
87
genericVarArg ( mo) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'genericVarArg'}}
92
88
93
- takeGeneric ( ( mo, 5 ) ) // expected-error {{tuple with noncopyable element type 'MO' is not supported }}
94
- takeGeneric ( ( ( mo, 5 ) , 19 ) ) // expected-error {{tuple with noncopyable element type 'MO' is not supported }}
95
- takeGenericSendable ( ( mo, mo) ) // expected-error 2{{tuple with noncopyable element type 'MO' is not supported }}
89
+ takeGeneric ( ( mo, 5 ) ) // expected-error {{global function 'takeGeneric' requires that 'MO' conform to 'Copyable' }}
90
+ takeGeneric ( ( ( mo, 5 ) , 19 ) ) // expected-error {{global function 'takeGeneric' requires that 'MO' conform to 'Copyable' }}
91
+ takeGenericSendable ( ( mo, mo) ) // expected-error {{global function 'takeGenericSendable' requires that 'MO' conform to 'Copyable' }}
96
92
97
93
let singleton : ( MO ) = ( mo)
98
94
takeGeneric ( singleton) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'takeGeneric'}}
99
95
100
- takeAny ( ( mo) ) // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any '}}
101
- takeAny ( ( mo, mo) ) // expected-error {{noncopyable type '(MO, MO)' cannot be erased to copyable existential type 'Any '}}
96
+ takeAny ( ( mo) ) // expected-error {{argument type 'MO' does not conform to expected type 'Copyable '}}
97
+ takeAny ( ( mo, mo) ) // expected-error {{global function 'takeAny' requires that 'MO' conform to 'Copyable '}}
102
98
}
103
99
104
100
func checkBasicBoxes( ) {
@@ -154,22 +150,24 @@ func checkCasting(_ b: any Box, _ mo: borrowing MO, _ a: Any) {
154
150
let _: MO = dup. get ( )
155
151
let _: MO = dup. val
156
152
157
- let _: Any = MO . self // expected-error {{metatype 'MO.Type' cannot be cast to 'Any' because 'MO' is noncopyable}}
158
- let _: AnyObject = MO . self // expected-error {{metatype 'MO.Type' cannot be cast to 'AnyObject' because 'MO' is noncopyable}}
159
- let _ = MO . self as Any // expected-error {{metatype 'MO.Type' cannot be cast to 'Any' because 'MO' is noncopyable}}
160
- let _ = MO . self is Any // expected-warning {{cast from 'MO.Type' to unrelated type 'Any' always fails}}
153
+ let _: Any = MO . self
154
+ let _: AnyObject = MO . self // expected-error {{value of type 'MO.Type' expected to be instance of class or class-constrained type}}
155
+ let _ = MO . self as Any
156
+ let _ = MO . self is Any // expected-warning {{'is' test is always true}}
157
+
158
+ // FIXME: well this message is confusing. It's actually that `any Sendable` requires Copyable, not protocol `Sendable`!
159
+ let _: Sendable = ( MO ( ) , MO ( ) ) // expected-error {{protocol 'Sendable' requires that 'MO' conform to 'Copyable'}}
161
160
162
- let _: Sendable = ( MO ( ) , MO ( ) ) // expected-error {{noncopyable type '(MO, MO)' cannot be erased to copyable existential type 'any Sendable'}}
163
- let _: Sendable = MO ( ) // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any Sendable'}}
164
- let _: Copyable = mo // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any Copyable'}}
165
- let _: AnyObject = MO ( ) // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'AnyObject'}}
166
- let _: Any = mo // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any'}}
161
+ let _: Sendable = MO ( ) // expected-error {{value of type 'MO' does not conform to specified type 'Copyable'}}
162
+ let _: Copyable = mo // expected-error {{value of type 'MO' does not conform to specified type 'Copyable'}}
163
+ let _: AnyObject = MO ( ) // expected-error {{value of type 'MO' expected to be instance of class or class-constrained type}}
164
+ let _: Any = mo // expected-error {{value of type 'MO' does not conform to specified type 'Copyable'}}
167
165
168
- _ = MO ( ) as P // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any P'}}
169
- _ = MO ( ) as any P // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'any P'}}
170
- _ = MO ( ) as Any // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'Any'}}
166
+ _ = MO ( ) as P // expected-error {{cannot convert value of type 'MO' to type 'any P' in coercion }}
167
+ _ = MO ( ) as any P // expected-error {{cannot convert value of type 'MO' to type 'any P' in coercion }}
168
+ _ = MO ( ) as Any // expected-error {{cannot convert value of type 'MO' to type 'Any' in coercion }}
171
169
_ = MO ( ) as MO
172
- _ = MO ( ) as AnyObject // expected-error {{noncopyable type 'MO' cannot be erased to copyable existential type 'AnyObject' }}
170
+ _ = MO ( ) as AnyObject // expected-error {{value of type 'MO' expected to be instance of class or class-constrained type }}
173
171
_ = 5 as MO // expected-error {{cannot convert value of type 'Int' to type 'MO' in coercion}}
174
172
_ = a as MO // expected-error {{cannot convert value of type 'Any' to type 'MO' in coercion}}
175
173
_ = b as MO // expected-error {{cannot convert value of type 'any Box' to type 'MO' in coercion}}
@@ -236,17 +234,17 @@ func checkStdlibTypes(_ mo: borrowing MO) {
236
234
_ = " \( mo) " // expected-error {{no exact matches in call to instance method 'appendInterpolation'}}
237
235
let _: String = String ( describing: mo) // expected-error {{no exact matches in call to initializer}}
238
236
239
- let _: [ MO ] = // MISSING -error {{noncopyable type 'MO' cannot be used with generic type 'Array<Element>' yet }}
237
+ let _: [ MO ] = // expected -error {{type 'MO' does not conform to protocol 'Copyable' }}
240
238
[ MO ( ) , MO ( ) ]
241
- let _: [ MO ] = // MISSING -error {{noncopyable type 'MO' cannot be used with generic type 'Array<Element>' yet }}
239
+ let _: [ MO ] = // expected -error {{type 'MO' does not conform to protocol 'Copyable' }}
242
240
[ ]
243
241
let _: [ String : MO ] = // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
244
242
[ " hello " : MO ( ) ] // expected-error{{type '(String, MO)' containing noncopyable element is not supported}}
245
243
246
244
_ = [ MO ( ) ] // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'Element' in 'Array'}}
247
245
248
246
let _: Array < MO > = . init( ) // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
249
- _ = [ MO] ( ) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'Element' in 'Array '}}
247
+ _ = [ MO] ( ) // expected-error {{type 'MO' does not conform to protocol 'Copyable '}}
250
248
251
249
let _: String = " hello \( mo) " // expected-error {{no exact matches in call to instance method 'appendInterpolation'}}
252
250
}
0 commit comments