From 174bbd2586f63e328e740ca63e492a760cf314ac Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 25 May 2022 16:12:03 -0700 Subject: [PATCH] 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 --- lib/Sema/CSSimplify.cpp | 10 +++++++--- test/Constraints/argument_matching.swift | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index d416cd065fd3f..6b1f3ed9f86c0 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -4896,9 +4896,13 @@ bool ConstraintSystem::repairFailures( if (!(overload && overload->choice.isDecl())) return true; - if (!getParameterList(overload->choice.getDecl()) - ->get(applyLoc->getParamIdx()) - ->getTypeOfDefaultExpr()) + // Ignore decls that don't have meaningful parameter lists - this + // matches variables and parameters with function types. + auto *paramList = getParameterList(overload->choice.getDecl()); + if (!paramList) + return true; + + if (!paramList->get(applyLoc->getParamIdx())->getTypeOfDefaultExpr()) return true; } } diff --git a/test/Constraints/argument_matching.swift b/test/Constraints/argument_matching.swift index 291d2cd95ca9a..c3ff7d144c50b 100644 --- a/test/Constraints/argument_matching.swift +++ b/test/Constraints/argument_matching.swift @@ -1782,3 +1782,10 @@ func testExtraTrailingClosure() { func qux(x: () -> Void, y: () -> Void, z: () -> Void) {} // expected-note {{'qux(x:y:z:)' declared here}} qux() {} m: {} y: {} n: {} z: {} o: {} // expected-error@:6 {{extra trailing closures at positions #2, #4, #6 in call}} } + +// rdar://93922410 - argument-to-parameter doesn't handle applies of ParamDecls +func rdar93922410(_ completion: (Int?) -> Void) { // expected-note {{'completion' declared here}} + _ = { + return completion() // expected-error {{missing argument for parameter #1 in call}} + } +}