Skip to content

Commit 1dedba1

Browse files
committed
Sema: Pass argument match kind down to matchCallArguments()
1 parent 5938f5a commit 1dedba1

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7848,6 +7848,7 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
78487848
auto openedFuncType = openedType->castTo<FunctionType>();
78497849
::matchCallArguments(
78507850
cs, args, openedFuncType->getParams(),
7851+
ConstraintKind::ArgumentConversion,
78517852
cs.getConstraintLocator(call, ConstraintLocator::ApplyArgument));
78527853

78537854
// Solve the system.

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ namespace {
12921292
AnyFunctionType::decomposeInput(constrParamType, params);
12931293

12941294
::matchCallArguments(
1295-
CS, args, params,
1295+
CS, args, params, ConstraintKind::ArgumentConversion,
12961296
CS.getConstraintLocator(expr, ConstraintLocator::ApplyArgument));
12971297

12981298
Type result = tv;

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,8 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
938938
// Match the argument of a call to the parameter.
939939
ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
940940
ConstraintSystem &cs, ArrayRef<AnyFunctionType::Param> args,
941-
ArrayRef<AnyFunctionType::Param> params, ConstraintLocatorBuilder locator) {
941+
ArrayRef<AnyFunctionType::Param> params, ConstraintKind subKind,
942+
ConstraintLocatorBuilder locator) {
942943
// Extract the parameters.
943944
ValueDecl *callee;
944945
bool hasCurriedSelf;
@@ -971,12 +972,6 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
971972
// assignment operators.
972973
auto *anchor = locator.getAnchor();
973974
assert(anchor && "locator without anchor expression?");
974-
bool isOperator = (isa<PrefixUnaryExpr>(anchor) ||
975-
isa<PostfixUnaryExpr>(anchor) || isa<BinaryExpr>(anchor));
976-
977-
ConstraintKind subKind = (isOperator
978-
? ConstraintKind::OperatorArgumentConversion
979-
: ConstraintKind::ArgumentConversion);
980975

981976
// Check whether argument of the call at given position refers to
982977
// parameter marked as `@autoclosure`. This function is used to
@@ -5605,6 +5600,12 @@ ConstraintSystem::simplifyApplicableFnConstraint(
56055600

56065601
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
56075602

5603+
SmallVector<LocatorPathElt, 2> parts;
5604+
Expr *anchor = locator.getLocatorParts(parts);
5605+
bool isOperator = (isa<PrefixUnaryExpr>(anchor) ||
5606+
isa<PostfixUnaryExpr>(anchor) ||
5607+
isa<BinaryExpr>(anchor));
5608+
56085609
// If the types are obviously equivalent, we're done.
56095610
if (type1.getPointer() == desugar2)
56105611
return SolutionKind::Solved;
@@ -5640,8 +5641,6 @@ ConstraintSystem::simplifyApplicableFnConstraint(
56405641

56415642
// Strip the 'ApplyFunction' off the locator.
56425643
// FIXME: Perhaps ApplyFunction can go away entirely?
5643-
SmallVector<LocatorPathElt, 2> parts;
5644-
Expr *anchor = locator.getLocatorParts(parts);
56455644
assert(!parts.empty() && "Nonsensical applicable-function locator");
56465645
assert(parts.back().getKind() == ConstraintLocator::ApplyFunction);
56475646
assert(parts.back().getNewSummaryFlags() == 0);
@@ -5670,9 +5669,13 @@ ConstraintSystem::simplifyApplicableFnConstraint(
56705669

56715670
// For a function, bind the output and convert the argument to the input.
56725671
if (auto func2 = dyn_cast<FunctionType>(desugar2)) {
5672+
ConstraintKind subKind = (isOperator
5673+
? ConstraintKind::OperatorArgumentConversion
5674+
: ConstraintKind::ArgumentConversion);
5675+
56735676
// The argument type must be convertible to the input type.
56745677
if (::matchCallArguments(
5675-
*this, func1->getParams(), func2->getParams(),
5678+
*this, func1->getParams(), func2->getParams(), subKind,
56765679
outerLocator.withPathElement(ConstraintLocator::ApplyArgument))
56775680
.isFailure())
56785681
return SolutionKind::Error;

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,7 @@ ConstraintSystem::TypeMatchResult
37433743
matchCallArguments(ConstraintSystem &cs,
37443744
ArrayRef<AnyFunctionType::Param> args,
37453745
ArrayRef<AnyFunctionType::Param> params,
3746+
ConstraintKind subKind,
37463747
ConstraintLocatorBuilder locator);
37473748

37483749
/// Given an expression that is the target of argument labels (for a call,

0 commit comments

Comments
 (0)