Skip to content

Commit c3eb22a

Browse files
committed
[test] test generic params with implicit some
1 parent 3a20ff0 commit c3eb22a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

test/type/implicit_some/opaque_parameters.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ func consumingA(fn: (P) -> Void) { } // expected-error{{'some' cannot appear in
6262
func consumingB(fn: FnType<P>) { } // expected-error{{'some' cannot appear in parameter position in parameter type '(P) -> Void'}}
6363

6464

65-
// TO-DO Handle plain generic opaque parameters
6665
func takePrimaryCollections(
67-
_ strings:some Collection<String>,
68-
_ ints : some Collection<Int>
66+
_ strings: Collection<String>,
67+
_ ints : Collection<Int>
6968
) {
7069
for s in strings {
7170
let _: String = s
@@ -75,9 +74,8 @@ func takePrimaryCollections(
7574
let _: Int = i
7675
}
7776
}
78-
// TO-DO Handle plain generic opaque parameters
7977
func takeMatchedPrimaryCollections<T: Equatable>(
80-
_ first: some Collection<T>, _ second: some Collection<T>
78+
_ first: Collection<T>, _ second: Collection<T>
8179
) -> Bool {
8280
first.elementsEqual(second)
8381
}

test/type/implicit_some/opaque_return.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,14 @@ enum E {
125125
protocol Q {
126126
func f() -> Int
127127
}
128+
129+
func findBiggerCollection<T : Numeric>( _ first: Collection<T>, _ second: Collection<T>) -> Collection<T> {
130+
// expected-error@-1 {{function declares an opaque return type 'Collection<T>', but the return statements in its body do not have matching underlying types}}
131+
if (first.count > second.count) { return first } //expected-note {{return statement has underlying type 'Collection<T>'}}
132+
return second //expected-note {{return statement has underlying type 'Collection<T>'}}
133+
}
134+
135+
func createCollection() -> Collection<Int> {
136+
let a = [9,2,0]
137+
return a
138+
}

0 commit comments

Comments
 (0)