Skip to content

Commit 91823fd

Browse files
committed
[CSBindings] Record holes only after all binding inference steps are done
If there are no direct, transitive or default bindings only then consider binding the given type variable to a "hole".
1 parent 248341a commit 91823fd

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ void ConstraintSystem::PotentialBindings::finalize(
139139
binding.BindingType = OptionalType::get(binding.BindingType);
140140
}
141141
}
142+
143+
// If there are no bindings, typeVar may be a hole.
144+
if (cs.shouldAttemptFixes() && Bindings.empty() &&
145+
TypeVar->getImpl().canBindToHole()) {
146+
IsHole = true;
147+
// If the base of the unresolved member reference like `.foo`
148+
// couldn't be resolved we'd want to bind it to a hole at the
149+
// very last moment possible, just like generic parameters.
150+
auto *locator = TypeVar->getImpl().getLocator();
151+
if (locator->isLastElement<LocatorPathElt::MemberRefBase>())
152+
PotentiallyIncomplete = true;
153+
154+
addPotentialBinding(PotentialBinding::forHole(cs.getASTContext(), locator));
155+
}
142156
}
143157

144158
Optional<ConstraintSystem::PotentialBindings>
@@ -858,21 +872,6 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
858872
result.addPotentialBinding({type, AllowedBindingKind::Exact, constraint});
859873
}
860874

861-
// If there are no bindings, typeVar may be a hole.
862-
if (shouldAttemptFixes() && result.Bindings.empty() &&
863-
typeVar->getImpl().canBindToHole()) {
864-
result.IsHole = true;
865-
// If the base of the unresolved member reference like `.foo`
866-
// couldn't be resolved we'd want to bind it to a hole at the
867-
// very last moment possible, just like generic parameters.
868-
auto *locator = typeVar->getImpl().getLocator();
869-
if (locator->isLastElement<LocatorPathElt::MemberRefBase>())
870-
result.PotentiallyIncomplete = true;
871-
872-
result.addPotentialBinding(
873-
PotentialBinding::forHole(getASTContext(), locator));
874-
}
875-
876875
// Determine if the bindings only constrain the type variable from above with
877876
// an existential type; such a binding is not very helpful because it's
878877
// impossible to enumerate the existential type's subtypes.

0 commit comments

Comments
 (0)