@@ -10549,17 +10549,20 @@ ConstraintSystem::simplifyApplicableFnConstraint(
10549
10549
};
10550
10550
10551
10551
// Local function to form an unsolved result.
10552
- auto formUnsolved = [&] {
10552
+ auto formUnsolved = [&]( bool activate = false ) {
10553
10553
if (flags.contains (TMF_GenerateConstraints)) {
10554
- addUnsolvedConstraint (
10555
- Constraint::createApplicableFunction (
10554
+ auto *application = Constraint::createApplicableFunction (
10556
10555
*this , type1, type2, trailingClosureMatching,
10557
- getConstraintLocator (locator)));
10556
+ getConstraintLocator (locator));
10557
+
10558
+ addUnsolvedConstraint (application);
10559
+ if (activate)
10560
+ activateConstraint (application);
10561
+
10558
10562
return SolutionKind::Solved;
10559
10563
}
10560
10564
10561
10565
return SolutionKind::Unsolved;
10562
-
10563
10566
};
10564
10567
10565
10568
// If right-hand side is a type variable, the constraint is unsolved.
@@ -10695,6 +10698,26 @@ ConstraintSystem::simplifyApplicableFnConstraint(
10695
10698
if (instance2->isTypeVariableOrMember ())
10696
10699
return formUnsolved ();
10697
10700
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
+
10698
10721
// Construct the instance from the input arguments.
10699
10722
auto simplified = simplifyConstructionConstraint (instance2, func1, subflags,
10700
10723
/* FIXME?*/ DC,
0 commit comments