Skip to content

Commit 85f742e

Browse files
committed
Test: update inverse_copyable_requirement.swift
1 parent bb57e4b commit 85f742e

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

test/Generics/inverse_copyable_requirement.swift

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// RUN: %target-typecheck-verify-swift -enable-experimental-feature NoncopyableGenerics
22

3-
// XFAIL: noncopyable_generics
4-
5-
// REQUIRES: noncopyable_generics
6-
73
// a concrete move-only type
84
struct MO: ~Copyable {
95
var x: Int?
@@ -71,8 +67,8 @@ takeGeneric(globalMO) // expected-error {{noncopyable type 'MO' cannot be substi
7167

7268

7369
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'}}
7672
}
7773

7874
func testBasic(_ mo: borrowing MO) {
@@ -83,22 +79,22 @@ func testBasic(_ mo: borrowing MO) {
8379
takeGeneric(MO()) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'takeGeneric'}}
8480
takeGeneric(mo) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'takeGeneric'}}
8581

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'}}
8884

8985
takeGeneric { () -> Int? in mo.x }
9086
genericVarArg(5)
9187
genericVarArg(mo) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'genericVarArg'}}
9288

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'}}
9692

9793
let singleton : (MO) = (mo)
9894
takeGeneric(singleton) // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'takeGeneric'}}
9995

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'}}
10298
}
10399

104100
func checkBasicBoxes() {
@@ -154,22 +150,24 @@ func checkCasting(_ b: any Box, _ mo: borrowing MO, _ a: Any) {
154150
let _: MO = dup.get()
155151
let _: MO = dup.val
156152

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'}}
161160

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'}}
167165

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}}
171169
_ = 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}}
173171
_ = 5 as MO // expected-error {{cannot convert value of type 'Int' to type 'MO' in coercion}}
174172
_ = a as MO // expected-error {{cannot convert value of type 'Any' to type 'MO' in coercion}}
175173
_ = 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) {
236234
_ = "\(mo)" // expected-error {{no exact matches in call to instance method 'appendInterpolation'}}
237235
let _: String = String(describing: mo) // expected-error {{no exact matches in call to initializer}}
238236

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'}}
240238
[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'}}
242240
[]
243241
let _: [String: MO] = // expected-error {{type 'MO' does not conform to protocol 'Copyable'}}
244242
["hello" : MO()] // expected-error{{type '(String, MO)' containing noncopyable element is not supported}}
245243

246244
_ = [MO()] // expected-error {{noncopyable type 'MO' cannot be substituted for copyable generic parameter 'Element' in 'Array'}}
247245

248246
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'}}
250248

251249
let _: String = "hello \(mo)" // expected-error {{no exact matches in call to instance method 'appendInterpolation'}}
252250
}

0 commit comments

Comments
 (0)