Skip to content

Commit c6b6e72

Browse files
committed
[CS] Tighten up assertions for getCalleeDeclAndArgs
Assert that we have a correct locator and that we recorded argument information for it, rather than returning no information. In addition, always return the callee locator, even if there is no callee.
1 parent 7e829d7 commit c6b6e72

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -770,45 +770,25 @@ static std::tuple<ValueDecl *, bool, ArrayRef<Identifier>, bool,
770770
ConstraintLocator *>
771771
getCalleeDeclAndArgs(ConstraintSystem &cs,
772772
ConstraintLocatorBuilder callBuilder) {
773-
auto formUnknownCallee =
774-
[]() -> std::tuple<ValueDecl *, bool, ArrayRef<Identifier>, bool,
775-
ConstraintLocator *> {
776-
return std::make_tuple(/*decl*/ nullptr, /*hasAppliedSelf*/ false,
777-
/*argLabels*/ ArrayRef<Identifier>(),
778-
/*hasTrailingClosure*/ false,
779-
/*calleeLocator*/ nullptr);
780-
};
781-
782773
auto *callLocator = cs.getConstraintLocator(callBuilder);
783-
auto *callExpr = callLocator->getAnchor();
784-
785-
// Break down the call.
786-
if (!callExpr)
787-
return formUnknownCallee();
788-
789-
// Our remaining path can only be 'ApplyArgument'.
790-
auto path = callLocator->getPath();
791-
if (!path.empty() && !path.back().is<LocatorPathElt::ApplyArgument>())
792-
return formUnknownCallee();
774+
assert(callLocator->isLastElement<LocatorPathElt::ApplyArgument>());
793775

794-
// Dig out the callee information.
776+
// Dig out the argument information.
795777
auto argInfo = cs.getArgumentInfo(callLocator);
796-
if (!argInfo)
797-
return formUnknownCallee();
778+
assert(argInfo);
798779

799780
auto argLabels = argInfo->Labels;
800781
auto hasTrailingClosure = argInfo->HasTrailingClosure;
801-
auto calleeLocator = cs.getCalleeLocator(callLocator);
802782

803783
// Find the overload choice corresponding to the callee locator.
784+
auto *calleeLocator = cs.getCalleeLocator(callLocator);
804785
auto selectedOverload = cs.findSelectedOverloadFor(calleeLocator);
805786

806787
// If we didn't find any matching overloads, we're done. Just return the
807788
// argument info.
808789
if (!selectedOverload)
809790
return std::make_tuple(/*decl*/ nullptr, /*hasAppliedSelf*/ false,
810-
argLabels, hasTrailingClosure,
811-
/*calleeLocator*/ nullptr);
791+
argLabels, hasTrailingClosure, calleeLocator);
812792

813793
// Return the found declaration, assuming there is one.
814794
auto choice = selectedOverload->choice;

0 commit comments

Comments
 (0)