File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -13394,8 +13394,12 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1339413394 choiceType = objectType;
1339513395 }
1339613396
13397+ // FIXME: The !getSelfProtocolDecl() check is load-bearing, because
13398+ // this optimization interacts poorly with existential opening
13399+ // somehow. It should all be removed.
1339713400 if (auto *choiceFnType = choiceType->getAs<FunctionType>()) {
13398- if (isa<ConstructorDecl>(choice.getDecl())) {
13401+ if (isa<ConstructorDecl>(choice.getDecl()) &&
13402+ !choice.getDecl()->getDeclContext()->getSelfProtocolDecl()) {
1339913403 auto choiceResultType = choice.getBaseType()
1340013404 ->getRValueType()
1340113405 ->getMetatypeInstanceType();
Original file line number Diff line number Diff line change 1+ // RUN: %target-typecheck-verify-swift
2+
3+ protocol P { }
4+
5+ func g( _: some P ) { }
6+ // expected-note@-1 {{required by global function 'g' where 'some P' = 'any P'}}
7+
8+ // rdar://problem/160389221
9+ func good( _ x: Array < any P > ) {
10+ Array ( x) . forEach { y in g ( y) }
11+ }
12+
13+ extension Array {
14+ var ffirst : Element ? { fatalError ( ) }
15+ func ffirst( wwhere: ( Element ) -> Bool ) -> Element { fatalError ( ) }
16+ }
17+
18+ func bad( _ x: Array < any P > ) {
19+ let y = x. ffirst!
20+ g ( y) // ok
21+
22+ let yy = x. ffirst
23+ g ( yy!) // ok
24+
25+ // FIXME: This is broken
26+
27+ g ( x. ffirst!)
28+ // expected-error@-1 {{type 'any P' cannot conform to 'P'}}
29+ // expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
30+ }
You can’t perform that action at this time.
0 commit comments