mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Partially revert existential opening fix
Selectively revert 36683a804c 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.
This commit is contained in:
@@ -256,11 +256,22 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
|
||||
if (auto *pack = type->getAs<PackType>()) {
|
||||
auto info = GenericParameterReferenceInfo();
|
||||
|
||||
for (auto arg : pack->getElementTypes()) {
|
||||
info |= findGenericParameterReferencesRec(
|
||||
genericSig, origParam, openedParam, arg,
|
||||
TypePosition::Invariant, /*canBeCovariantResult=*/false);
|
||||
}
|
||||
// FIXME: Source compatibility remedy to allow existential opening in
|
||||
// the following case:
|
||||
// ```
|
||||
// protocol P {}
|
||||
// struct S<each T> {}
|
||||
// func foo<T: P>(_: T, _: S<T>? = nil) {}
|
||||
// let p: any P
|
||||
// foo(p)
|
||||
// ```
|
||||
//
|
||||
// for (auto arg : pack->getElementTypes()) {
|
||||
// info |= findGenericParameterReferencesRec(
|
||||
// genericSig, origParam, openedParam, arg,
|
||||
// TypePosition::Invariant, /*canBeCovariantResult=*/false);
|
||||
// }
|
||||
(void)pack;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
11
test/Constraints/opened_existentials_default_arg.swift
Normal file
11
test/Constraints/opened_existentials_default_arg.swift
Normal file
@@ -0,0 +1,11 @@
|
||||
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple
|
||||
|
||||
do {
|
||||
protocol P {}
|
||||
struct S<each T> {}
|
||||
|
||||
func foo<T: P>(_: T, _: Optional<S<T>> = nil) {}
|
||||
|
||||
let p: any P
|
||||
foo(p) // OK
|
||||
}
|
||||
@@ -50,19 +50,6 @@ func bar(a: any HasSameShape) -> (Int, String) {
|
||||
a.foo(t: 1, u: "hi")
|
||||
}
|
||||
|
||||
// Make sure we look through a pack type when evaluating the variance of the result
|
||||
struct Variadic<each A> {}
|
||||
|
||||
protocol VariadicResult {
|
||||
associatedtype A
|
||||
func foo() -> Variadic<A>
|
||||
}
|
||||
|
||||
func variadicResult(a: any VariadicResult) {
|
||||
a.foo()
|
||||
// expected-error@-1 {{member 'foo' cannot be used on value of type 'any VariadicResult'; consider using a generic constraint instead}}
|
||||
}
|
||||
|
||||
// Pack expansions are invariant
|
||||
struct Pair<X, Y> {}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// RUN: not --crash %target-swift-frontend -typecheck -target %target-swift-5.9-abi-triple %s
|
||||
|
||||
struct Variadic<each A> {}
|
||||
|
||||
protocol VariadicResult {
|
||||
associatedtype A
|
||||
func foo() -> Variadic<A>
|
||||
}
|
||||
|
||||
func variadicResult(a: any VariadicResult) {
|
||||
a.foo()
|
||||
}
|
||||
Reference in New Issue
Block a user