@@ -3771,13 +3771,6 @@ bool ConstraintSystem::repairFailures(
37713771 });
37723772 };
37733773
3774- auto markAnyTypeVarsAsPotentialHoles = [&](Type type) {
3775- type.visit ([&](Type subType) {
3776- if (auto *typeVar = subType->getAs <TypeVariableType>())
3777- recordPotentialHole (typeVar);
3778- });
3779- };
3780-
37813774 if (repairArrayLiteralUsedAsDictionary (*this , lhs, rhs, matchKind,
37823775 conversionsOrFixes,
37833776 getConstraintLocator (locator)))
@@ -4721,10 +4714,7 @@ bool ConstraintSystem::repairFailures(
47214714 // of the conversion (or pattern match) to have holes. This
47224715 // helps when conversion if between a type and a tuple e.g.
47234716 // `Int` vs. `(_, _)`.
4724- rhs.visit ([&](Type type) {
4725- if (auto *typeVar = type->getAs <TypeVariableType>())
4726- recordPotentialHole (typeVar);
4727- });
4717+ recordAnyTypeVarAsPotentialHole (rhs);
47284718
47294719 conversionsOrFixes.push_back (CollectionElementContextualMismatch::create (
47304720 *this , lhs, rhs, getConstraintLocator (locator)));
@@ -4803,8 +4793,8 @@ bool ConstraintSystem::repairFailures(
48034793 }
48044794
48054795 case ConstraintLocator::TernaryBranch: {
4806- markAnyTypeVarsAsPotentialHoles (lhs);
4807- markAnyTypeVarsAsPotentialHoles (rhs);
4796+ recordAnyTypeVarAsPotentialHole (lhs);
4797+ recordAnyTypeVarAsPotentialHole (rhs);
48084798
48094799 // If `if` expression has a contextual type, let's consider it a source of
48104800 // truth and produce a contextual mismatch instead of per-branch failure,
@@ -4844,8 +4834,8 @@ bool ConstraintSystem::repairFailures(
48444834 // element pattern, call it a contextual mismatch.
48454835 auto pattern = elt.castTo <LocatorPathElt::PatternMatch>().getPattern ();
48464836 if (lhs->is <FunctionType>() && isa<EnumElementPattern>(pattern)) {
4847- markAnyTypeVarsAsPotentialHoles (lhs);
4848- markAnyTypeVarsAsPotentialHoles (rhs);
4837+ recordAnyTypeVarAsPotentialHole (lhs);
4838+ recordAnyTypeVarAsPotentialHole (rhs);
48494839
48504840 conversionsOrFixes.push_back (ContextualMismatch::create (
48514841 *this , lhs, rhs, getConstraintLocator (locator)));
@@ -8344,10 +8334,7 @@ ConstraintSystem::simplifyValueWitnessConstraint(
83448334 if (!shouldAttemptFixes ())
83458335 return SolutionKind::Error;
83468336
8347- memberType.visit ([&](Type type) {
8348- if (auto *typeVar = type->getAs <TypeVariableType>())
8349- recordPotentialHole (typeVar);
8350- });
8337+ recordAnyTypeVarAsPotentialHole (memberType);
83518338
83528339 return SolutionKind::Solved;
83538340 }
@@ -8492,11 +8479,7 @@ ConstraintSystem::simplifyOneWayConstraint(
84928479
84938480 // Propagate holes through one-way constraints.
84948481 if (secondSimplified->isPlaceholder ()) {
8495- first.visit ([&](Type subType) {
8496- if (auto *typeVar = subType->getAs <TypeVariableType>())
8497- recordPotentialHole (typeVar);
8498- });
8499-
8482+ recordAnyTypeVarAsPotentialHole (first);
85008483 return SolutionKind::Solved;
85018484 }
85028485
@@ -9944,7 +9927,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
99449927 if (auto *typeVar = type2->getAs <TypeVariableType>()) {
99459928 auto *locator = typeVar->getImpl ().getLocator ();
99469929 if (typeVar->isPlaceholder () || hasFixFor (locator))
9947- recordPotentialHole (func1);
9930+ recordAnyTypeVarAsPotentialHole (func1);
99489931 }
99499932 }
99509933
@@ -10176,7 +10159,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
1017610159
1017710160 // If there are any type variables associated with arguments/result
1017810161 // they have to be marked as "holes".
10179- recordPotentialHole (func1);
10162+ recordAnyTypeVarAsPotentialHole (func1);
1018010163
1018110164 if (desugar2->isPlaceholder ())
1018210165 return SolutionKind::Solved;
@@ -10450,7 +10433,7 @@ ConstraintSystem::simplifyDynamicCallableApplicableFnConstraint(
1045010433 return SolutionKind::Error;
1045110434
1045210435 recordPotentialHole (tv);
10453- recordPotentialHole (func1);
10436+ recordAnyTypeVarAsPotentialHole (func1);
1045410437
1045510438 return SolutionKind::Solved;
1045610439 }
@@ -11149,8 +11132,14 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
1114911132 return false ;
1115011133}
1115111134
11152- void ConstraintSystem::recordPotentialHole (Type type) {
11153- assert (type->hasTypeVariable ());
11135+ void ConstraintSystem::recordPotentialHole (TypeVariableType *typeVar) {
11136+ typeVar->getImpl ().enableCanBindToHole (getSavedBindings ());
11137+ }
11138+
11139+ void ConstraintSystem::recordAnyTypeVarAsPotentialHole (Type type) {
11140+ if (!type->hasTypeVariable ())
11141+ return ;
11142+
1115411143 type.visit ([&](Type type) {
1115511144 if (auto *typeVar = type->getAs <TypeVariableType>())
1115611145 typeVar->getImpl ().enableCanBindToHole (getSavedBindings ());
@@ -11261,7 +11250,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1126111250 newTupleTypes.push_back (smallerElt);
1126211251 } else {
1126311252 if (largerElt.getType ()->isTypeVariableOrMember ())
11264- recordPotentialHole (largerElt.getType ());
11253+ recordAnyTypeVarAsPotentialHole (largerElt.getType ());
1126511254 }
1126611255 }
1126711256 auto matchingType =
0 commit comments