File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -10946,6 +10946,24 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1094610946
1094710947 auto *argList = getArgumentList(getConstraintLocator(locator));
1094810948
10949+ // If argument list has trailing closures and this is `init` call to
10950+ // a callable type, let's not filter anything since there is a possibility
10951+ // that it needs an implicit `.callAsFunction` to work.
10952+ if (argList && argList->hasAnyTrailingClosures()) {
10953+ if (disjunction->getLocator()
10954+ ->isLastElement<LocatorPathElt::ConstructorMember>()) {
10955+ auto choice = disjunction->getNestedConstraints()[0]->getOverloadChoice();
10956+ if (auto *decl = choice.getDeclOrNull()) {
10957+ auto *dc = decl->getDeclContext();
10958+ if (auto *parent = dc->getSelfNominalTypeDecl()) {
10959+ auto type = parent->getDeclaredInterfaceType();
10960+ if (type->isCallableNominalType(DC))
10961+ return false;
10962+ }
10963+ }
10964+ }
10965+ }
10966+
1094910967 // Consider each of the constraints in the disjunction.
1095010968retry_after_fail:
1095110969 bool hasUnhandledConstraints = false;
Original file line number Diff line number Diff line change @@ -29,3 +29,25 @@ struct Test {
2929 }
3030 }
3131}
32+
33+ // rdar://92912878 - filtering prevents disambiguation of `.callAsFunction`
34+ func test_no_filtering_of_overloads( ) {
35+ struct S {
36+ init ( ) { }
37+ init ( _: String ) { }
38+
39+ func callAsFunction< T> ( _ fn: ( ) -> T ) -> T {
40+ fn ( )
41+ }
42+ }
43+
44+ func test( _: ( ) -> Void ) {
45+ }
46+
47+ test {
48+ _ = S ( ) { // Ok
49+ _ = 42
50+ print ( " Hello " )
51+ }
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments