Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13394,8 +13394,12 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
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();
Expand Down
30 changes: 30 additions & 0 deletions test/Constraints/opened_existentials_overload.swift
Original file line number Diff line number Diff line change
@@ -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}}
}