|
1 |
| -// RUN: %target-typecheck-verify-swift -enable-experimental-opaque-parameters -disable-availability-checking |
| 1 | +// RUN: %target-typecheck-verify-swift -enable-experimental-opaque-parameters -enable-parametrized-protocol-types -disable-availability-checking |
2 | 2 |
|
3 | 3 | protocol P { }
|
4 | 4 |
|
@@ -50,3 +50,39 @@ func testTakeMultiple(
|
50 | 50 | takeMultiple(d, arrayOfInts, i)
|
51 | 51 | takeMultiple(d, arrayOfInts, arrayOfInts) // expected-error{{global function 'takeMultiple' requires that '[Int]' conform to 'P'}}
|
52 | 52 | }
|
| 53 | + |
| 54 | +// Combine with parameterized protocol types |
| 55 | +protocol PrimaryCollection: Collection { |
| 56 | + @_primaryAssociatedType associatedtype Element |
| 57 | +} |
| 58 | + |
| 59 | +extension Array: PrimaryCollection { } |
| 60 | +extension Set: PrimaryCollection { } |
| 61 | + |
| 62 | +func takePrimaryCollections( |
| 63 | + _ strings: some PrimaryCollection<String>, |
| 64 | + _ ints : some PrimaryCollection<Int> |
| 65 | +) { |
| 66 | + for s in strings { |
| 67 | + let _: String = s |
| 68 | + } |
| 69 | + |
| 70 | + for i in ints { |
| 71 | + let _: Int = i |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +func takeMatchedPrimaryCollections<T: Equatable>( |
| 76 | + _ first: some PrimaryCollection<T>, _ second: some PrimaryCollection<T> |
| 77 | +) -> Bool { |
| 78 | + first.elementsEqual(second) |
| 79 | +} |
| 80 | + |
| 81 | +func testPrimaries( |
| 82 | + arrayOfInts: [Int], setOfStrings: Set<String>, setOfInts: Set<Int> |
| 83 | +) { |
| 84 | + takePrimaryCollections(setOfStrings, setOfInts) |
| 85 | + takePrimaryCollections(setOfStrings, arrayOfInts) |
| 86 | + _ = takeMatchedPrimaryCollections(arrayOfInts, setOfInts) |
| 87 | + _ = takeMatchedPrimaryCollections(arrayOfInts, setOfStrings) // expected-error{{type of expression is ambiguous without more context}} |
| 88 | +} |
0 commit comments