mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #84501 from slavapestov/fix-rdar160389221
Sema: Workaround for broken existential opening behavior
This commit is contained in:
@@ -13394,8 +13394,12 @@ retry_after_fail:
|
||||
choiceType = objectType;
|
||||
}
|
||||
|
||||
// FIXME: The !getSelfProtocolDecl() check is load-bearing, because
|
||||
// this optimization interacts poorly with existential opening
|
||||
// somehow. It should all be removed.
|
||||
if (auto *choiceFnType = choiceType->getAs<FunctionType>()) {
|
||||
if (isa<ConstructorDecl>(choice.getDecl())) {
|
||||
if (isa<ConstructorDecl>(choice.getDecl()) &&
|
||||
!choice.getDecl()->getDeclContext()->getSelfProtocolDecl()) {
|
||||
auto choiceResultType = choice.getBaseType()
|
||||
->getRValueType()
|
||||
->getMetatypeInstanceType();
|
||||
|
||||
30
test/Constraints/opened_existentials_overload.swift
Normal file
30
test/Constraints/opened_existentials_overload.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
|
||||
protocol P {}
|
||||
|
||||
func g(_: some P) {}
|
||||
// expected-note@-1 {{required by global function 'g' where 'some P' = 'any P'}}
|
||||
|
||||
// rdar://problem/160389221
|
||||
func good(_ x: Array<any P>) {
|
||||
Array(x).forEach { y in g(y) }
|
||||
}
|
||||
|
||||
extension Array {
|
||||
var ffirst: Element? { fatalError() }
|
||||
func ffirst(wwhere: (Element) -> Bool) -> Element { fatalError() }
|
||||
}
|
||||
|
||||
func bad(_ x: Array<any P>) {
|
||||
let y = x.ffirst!
|
||||
g(y) // ok
|
||||
|
||||
let yy = x.ffirst
|
||||
g(yy!) // ok
|
||||
|
||||
// FIXME: This is broken
|
||||
|
||||
g(x.ffirst!)
|
||||
// expected-error@-1 {{type 'any P' cannot conform to 'P'}}
|
||||
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
|
||||
}
|
||||
Reference in New Issue
Block a user