Skip to content

Commit 66e12e8

Browse files
committed
Add a test mixing opaque parameters with primary associated types.
... beautiful.
1 parent d542cc1 commit 66e12e8

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

test/type/opaque_parameters.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22

33
protocol P { }
44

@@ -50,3 +50,39 @@ func testTakeMultiple(
5050
takeMultiple(d, arrayOfInts, i)
5151
takeMultiple(d, arrayOfInts, arrayOfInts) // expected-error{{global function 'takeMultiple' requires that '[Int]' conform to 'P'}}
5252
}
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

Comments
 (0)