@@ -3771,13 +3771,6 @@ bool ConstraintSystem::repairFailures(
3771
3771
});
3772
3772
};
3773
3773
3774
- auto markAnyTypeVarsAsPotentialHoles = [&](Type type) {
3775
- type.visit ([&](Type subType) {
3776
- if (auto *typeVar = subType->getAs <TypeVariableType>())
3777
- recordPotentialHole (typeVar);
3778
- });
3779
- };
3780
-
3781
3774
if (repairArrayLiteralUsedAsDictionary (*this , lhs, rhs, matchKind,
3782
3775
conversionsOrFixes,
3783
3776
getConstraintLocator (locator)))
@@ -4721,10 +4714,7 @@ bool ConstraintSystem::repairFailures(
4721
4714
// of the conversion (or pattern match) to have holes. This
4722
4715
// helps when conversion if between a type and a tuple e.g.
4723
4716
// `Int` vs. `(_, _)`.
4724
- rhs.visit ([&](Type type) {
4725
- if (auto *typeVar = type->getAs <TypeVariableType>())
4726
- recordPotentialHole (typeVar);
4727
- });
4717
+ recordAnyTypeVarAsPotentialHole (rhs);
4728
4718
4729
4719
conversionsOrFixes.push_back (CollectionElementContextualMismatch::create (
4730
4720
*this , lhs, rhs, getConstraintLocator (locator)));
@@ -4803,8 +4793,8 @@ bool ConstraintSystem::repairFailures(
4803
4793
}
4804
4794
4805
4795
case ConstraintLocator::TernaryBranch: {
4806
- markAnyTypeVarsAsPotentialHoles (lhs);
4807
- markAnyTypeVarsAsPotentialHoles (rhs);
4796
+ recordAnyTypeVarAsPotentialHole (lhs);
4797
+ recordAnyTypeVarAsPotentialHole (rhs);
4808
4798
4809
4799
// If `if` expression has a contextual type, let's consider it a source of
4810
4800
// truth and produce a contextual mismatch instead of per-branch failure,
@@ -4844,8 +4834,8 @@ bool ConstraintSystem::repairFailures(
4844
4834
// element pattern, call it a contextual mismatch.
4845
4835
auto pattern = elt.castTo <LocatorPathElt::PatternMatch>().getPattern ();
4846
4836
if (lhs->is <FunctionType>() && isa<EnumElementPattern>(pattern)) {
4847
- markAnyTypeVarsAsPotentialHoles (lhs);
4848
- markAnyTypeVarsAsPotentialHoles (rhs);
4837
+ recordAnyTypeVarAsPotentialHole (lhs);
4838
+ recordAnyTypeVarAsPotentialHole (rhs);
4849
4839
4850
4840
conversionsOrFixes.push_back (ContextualMismatch::create (
4851
4841
*this , lhs, rhs, getConstraintLocator (locator)));
@@ -8344,10 +8334,7 @@ ConstraintSystem::simplifyValueWitnessConstraint(
8344
8334
if (!shouldAttemptFixes ())
8345
8335
return SolutionKind::Error;
8346
8336
8347
- memberType.visit ([&](Type type) {
8348
- if (auto *typeVar = type->getAs <TypeVariableType>())
8349
- recordPotentialHole (typeVar);
8350
- });
8337
+ recordAnyTypeVarAsPotentialHole (memberType);
8351
8338
8352
8339
return SolutionKind::Solved;
8353
8340
}
@@ -8492,11 +8479,7 @@ ConstraintSystem::simplifyOneWayConstraint(
8492
8479
8493
8480
// Propagate holes through one-way constraints.
8494
8481
if (secondSimplified->isPlaceholder ()) {
8495
- first.visit ([&](Type subType) {
8496
- if (auto *typeVar = subType->getAs <TypeVariableType>())
8497
- recordPotentialHole (typeVar);
8498
- });
8499
-
8482
+ recordAnyTypeVarAsPotentialHole (first);
8500
8483
return SolutionKind::Solved;
8501
8484
}
8502
8485
@@ -9944,7 +9927,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
9944
9927
if (auto *typeVar = type2->getAs <TypeVariableType>()) {
9945
9928
auto *locator = typeVar->getImpl ().getLocator ();
9946
9929
if (typeVar->isPlaceholder () || hasFixFor (locator))
9947
- recordPotentialHole (func1);
9930
+ recordAnyTypeVarAsPotentialHole (func1);
9948
9931
}
9949
9932
}
9950
9933
@@ -10176,7 +10159,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
10176
10159
10177
10160
// If there are any type variables associated with arguments/result
10178
10161
// they have to be marked as "holes".
10179
- recordPotentialHole (func1);
10162
+ recordAnyTypeVarAsPotentialHole (func1);
10180
10163
10181
10164
if (desugar2->isPlaceholder ())
10182
10165
return SolutionKind::Solved;
@@ -10450,7 +10433,7 @@ ConstraintSystem::simplifyDynamicCallableApplicableFnConstraint(
10450
10433
return SolutionKind::Error;
10451
10434
10452
10435
recordPotentialHole (tv);
10453
- recordPotentialHole (func1);
10436
+ recordAnyTypeVarAsPotentialHole (func1);
10454
10437
10455
10438
return SolutionKind::Solved;
10456
10439
}
@@ -11149,8 +11132,14 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
11149
11132
return false ;
11150
11133
}
11151
11134
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
+
11154
11143
type.visit ([&](Type type) {
11155
11144
if (auto *typeVar = type->getAs <TypeVariableType>())
11156
11145
typeVar->getImpl ().enableCanBindToHole (getSavedBindings ());
@@ -11261,7 +11250,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
11261
11250
newTupleTypes.push_back (smallerElt);
11262
11251
} else {
11263
11252
if (largerElt.getType ()->isTypeVariableOrMember ())
11264
- recordPotentialHole (largerElt.getType ());
11253
+ recordAnyTypeVarAsPotentialHole (largerElt.getType ());
11265
11254
}
11266
11255
}
11267
11256
auto matchingType =
0 commit comments