mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Handle leading dot before calling isViableForRanking()
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -148,11 +148,11 @@ BindingSet SemaTest::inferBindings(ConstraintSystem &cs,
|
||||
bindings.inferTransitiveKeyPathBindings();
|
||||
(void) bindings.finalizeKeyPathBindings();
|
||||
|
||||
bindings.inferTransitiveSupertypeBindings();
|
||||
|
||||
bindings.inferTransitiveUnresolvedMemberRefBindings();
|
||||
bindings.finalizeUnresolvedMemberChainResult();
|
||||
|
||||
bindings.inferTransitiveSupertypeBindings();
|
||||
|
||||
bindings.determineLiteralCoverage();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user