Skip to content

Commit 662023a

Browse files
Merge pull request #79289 from AnthonyLatsis/fix-rdar141962317
[6.1] Sema: Partially revert existential opening fix
2 parents 5e79d63 + 38d3bbe commit 662023a

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
@@ -259,11 +259,22 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
259259
if (auto *pack = type->getAs<PackType>()) {
260260
auto info = GenericParameterReferenceInfo();
261261

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

268279
return info;
269280
}
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_accesses_self_assoctype.swift

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

1041-
// Make sure we look through a pack type when evaluating the variance of the result
1042-
struct Variadic<each A> {}
1043-
1044-
protocol VariadicResult {
1045-
associatedtype A
1046-
func foo() -> Variadic<A>
1047-
}
1048-
1049-
func variadicResult(a: any VariadicResult) {
1050-
a.foo()
1051-
// expected-error@-1 {{member 'foo' cannot be used on value of type 'any VariadicResult'; consider using a generic constraint instead}}
1052-
}
1053-
10541041
// Pack expansions are invariant
10551042
struct Pair<X, Y> {}
10561043

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)