Skip to content

Commit 2874ffe

Browse files
committed
Sema: Partially revert existential opening fix
Selectively revert 36683a8 to resolve a source compatibility regression. See inline comment for use case. We are going to consider acknowledging this use case in the rules in a future release.
1 parent 707ea39 commit 2874ffe

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
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+
}

0 commit comments

Comments
 (0)