Skip to content

Commit 70557f0

Browse files
committed
Handle ParamDecls and VarDecls in Argument Matching Diagnostics
These don't produce meaningful ParameterLists for this analysis to consider. Bail instead of crashing. rdar://93922410
1 parent c7e7e50 commit 70557f0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4898,9 +4898,13 @@ bool ConstraintSystem::repairFailures(
48984898
if (!(overload && overload->choice.isDecl()))
48994899
return true;
49004900

4901-
if (!getParameterList(overload->choice.getDecl())
4902-
->get(applyLoc->getParamIdx())
4903-
->getTypeOfDefaultExpr())
4901+
// Ignore decls that don't have meaningful parameter lists - this
4902+
// matches variables and parameters with function types.
4903+
auto *paramList = getParameterList(overload->choice.getDecl());
4904+
if (!paramList)
4905+
return true;
4906+
4907+
if (!paramList->get(applyLoc->getParamIdx())->getTypeOfDefaultExpr())
49044908
return true;
49054909
}
49064910
}

test/Constraints/argument_matching.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,3 +1782,10 @@ func testExtraTrailingClosure() {
17821782
func qux(x: () -> Void, y: () -> Void, z: () -> Void) {} // expected-note {{'qux(x:y:z:)' declared here}}
17831783
qux() {} m: {} y: {} n: {} z: {} o: {} // expected-error@:6 {{extra trailing closures at positions #2, #4, #6 in call}}
17841784
}
1785+
1786+
// rdar://93922410 - argument-to-parameter doesn't handle applies of ParamDecls
1787+
func rdar93922410(_ completion: (Int?) -> Void) { // expected-note {{'completion' declared here}}
1788+
_ = {
1789+
return completion() // expected-error {{missing argument for parameter #1 in call}}
1790+
}
1791+
}

0 commit comments

Comments
 (0)