Skip to content

Commit 2705212

Browse files
Merge pull request #79404 from AnthonyLatsis/fix-rdar141962317-6.2
Sema: Partially revert existential opening fix
2 parents 44c1bf7 + 43e82b4 commit 2705212

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

lib/Sema/OpenedExistentials.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,22 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
256256
if (auto *pack = type->getAs<PackType>()) {
257257
auto info = GenericParameterReferenceInfo();
258258

259-
for (auto arg : pack->getElementTypes()) {
260-
info |= findGenericParameterReferencesRec(
261-
genericSig, origParam, openedParam, arg,
262-
TypePosition::Invariant, /*canBeCovariantResult=*/false);
263-
}
259+
// FIXME: Source compatibility remedy to allow existential opening in
260+
// the following case:
261+
// ```
262+
// protocol P {}
263+
// struct S<each T> {}
264+
// func foo<T: P>(_: T, _: S<T>? = nil) {}
265+
// let p: any P
266+
// foo(p)
267+
// ```
268+
//
269+
// for (auto arg : pack->getElementTypes()) {
270+
// info |= findGenericParameterReferencesRec(
271+
// genericSig, origParam, openedParam, arg,
272+
// TypePosition::Invariant, /*canBeCovariantResult=*/false);
273+
// }
274+
(void)pack;
264275

265276
return info;
266277
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple
2+
3+
do {
4+
protocol P {}
5+
struct S<each T> {}
6+
7+
func foo<T: P>(_: T, _: Optional<S<T>> = nil) {}
8+
9+
let p: any P
10+
foo(p) // OK
11+
}

test/decl/protocol/existential_member_access/misc.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,6 @@ func bar(a: any HasSameShape) -> (Int, String) {
5050
a.foo(t: 1, u: "hi")
5151
}
5252

53-
// Make sure we look through a pack type when evaluating the variance of the result
54-
struct Variadic<each A> {}
55-
56-
protocol VariadicResult {
57-
associatedtype A
58-
func foo() -> Variadic<A>
59-
}
60-
61-
func variadicResult(a: any VariadicResult) {
62-
a.foo()
63-
// expected-error@-1 {{member 'foo' cannot be used on value of type 'any VariadicResult'; consider using a generic constraint instead}}
64-
}
65-
6653
// Pack expansions are invariant
6754
struct Pair<X, Y> {}
6855

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: not --crash %target-swift-frontend -typecheck -target %target-swift-5.9-abi-triple %s
2+
3+
struct Variadic<each A> {}
4+
5+
protocol VariadicResult {
6+
associatedtype A
7+
func foo() -> Variadic<A>
8+
}
9+
10+
func variadicResult(a: any VariadicResult) {
11+
a.foo()
12+
}

0 commit comments

Comments
 (0)