Sema: Handle leading dot before calling isViableForRanking()

This commit is contained in:
Slava Pestov
2025-11-14 15:16:53 -05:00
parent 403a11f79d
commit b7e0083478
3 changed files with 9 additions and 17 deletions

View File

@@ -1150,14 +1150,6 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
auto isViableForRanking = [this](const BindingSet &bindings) -> bool {
auto *typeVar = bindings.getTypeVariable();
// Type variable representing a base of unresolved member chain should
// always be considered viable for ranking since it's allow to infer
// types from transitive protocol requirements.
if (auto *locator = typeVar->getImpl().getLocator()) {
if (locator->isLastElement<LocatorPathElt::MemberRefBase>())
return true;
}
// If type variable is marked as a potential hole there is always going
// to be at least one binding available for it.
if (shouldAttemptFixes() && typeVar->getImpl().canBindToHole())
@@ -1180,6 +1172,11 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
if (!bindings.finalizeKeyPathBindings())
continue;
// Special handling for "leading-dot" unresolved member references,
// like .foo.
bindings.inferTransitiveUnresolvedMemberRefBindings();
bindings.finalizeUnresolvedMemberChainResult();
// Before attempting to infer transitive bindings let's check
// whether there are any viable "direct" bindings associated with
// current type variable, if there are none - it means that this type
@@ -1194,11 +1191,6 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
bindings.inferTransitiveSupertypeBindings();
// Special handling for "leading-dot" unresolved member references,
// like .foo.
bindings.inferTransitiveUnresolvedMemberRefBindings();
bindings.finalizeUnresolvedMemberChainResult();
bindings.determineLiteralCoverage();
if (!bindings.hasViableBindings() && !bindings.isDirectHole())

View File

@@ -128,11 +128,11 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
bindings.inferTransitiveKeyPathBindings();
(void) bindings.finalizeKeyPathBindings();
bindings.inferTransitiveSupertypeBindings();
bindings.inferTransitiveUnresolvedMemberRefBindings();
bindings.finalizeUnresolvedMemberChainResult();
bindings.inferTransitiveSupertypeBindings();
bindings.determineLiteralCoverage();
// Inferred a single transitive binding through `$T_float`.

View File

@@ -148,11 +148,11 @@ BindingSet SemaTest::inferBindings(ConstraintSystem &cs,
bindings.inferTransitiveKeyPathBindings();
(void) bindings.finalizeKeyPathBindings();
bindings.inferTransitiveSupertypeBindings();
bindings.inferTransitiveUnresolvedMemberRefBindings();
bindings.finalizeUnresolvedMemberChainResult();
bindings.inferTransitiveSupertypeBindings();
bindings.determineLiteralCoverage();
}