Skip to content

Commit 4acd8ca

Browse files
committed
[CSSimplify] Delay simplication of callable type construction constraint
Cannot do that during constraint generation because trailing closures require special handling.
1 parent 12497b7 commit 4acd8ca

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10549,17 +10549,20 @@ ConstraintSystem::simplifyApplicableFnConstraint(
1054910549
};
1055010550

1055110551
// Local function to form an unsolved result.
10552-
auto formUnsolved = [&] {
10552+
auto formUnsolved = [&](bool activate = false) {
1055310553
if (flags.contains(TMF_GenerateConstraints)) {
10554-
addUnsolvedConstraint(
10555-
Constraint::createApplicableFunction(
10554+
auto *application = Constraint::createApplicableFunction(
1055610555
*this, type1, type2, trailingClosureMatching,
10557-
getConstraintLocator(locator)));
10556+
getConstraintLocator(locator));
10557+
10558+
addUnsolvedConstraint(application);
10559+
if (activate)
10560+
activateConstraint(application);
10561+
1055810562
return SolutionKind::Solved;
1055910563
}
1056010564

1056110565
return SolutionKind::Unsolved;
10562-
1056310566
};
1056410567

1056510568
// If right-hand side is a type variable, the constraint is unsolved.
@@ -10695,6 +10698,26 @@ ConstraintSystem::simplifyApplicableFnConstraint(
1069510698
if (instance2->isTypeVariableOrMember())
1069610699
return formUnsolved();
1069710700

10701+
auto *argumentsLoc = getConstraintLocator(
10702+
outerLocator.withPathElement(ConstraintLocator::ApplyArgument));
10703+
10704+
auto *argumentList = getArgumentList(argumentsLoc);
10705+
assert(argumentList);
10706+
10707+
// Cannot simplify construction of callable types during constraint
10708+
// generation when trailing closures are present because such calls
10709+
// have special trailing closure matching semantics. It's unclear
10710+
// whether trailing arguments belong to `.init` or implicit
10711+
// `.callAsFunction` in this case.
10712+
//
10713+
// Note that the constraint has to be activate so that solver attempts
10714+
// once constraint generation is done.
10715+
if (getPhase() == ConstraintSystemPhase::ConstraintGeneration &&
10716+
argumentList->hasAnyTrailingClosures() &&
10717+
instance2->isCallableNominalType(DC)) {
10718+
return formUnsolved(/*activate=*/true);
10719+
}
10720+
1069810721
// Construct the instance from the input arguments.
1069910722
auto simplified = simplifyConstructionConstraint(instance2, func1, subflags,
1070010723
/*FIXME?*/ DC,

0 commit comments

Comments
 (0)