Skip to content

Commit b7e0083

Browse files
committed
Sema: Handle leading dot before calling isViableForRanking()
1 parent 403a11f commit b7e0083

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,14 +1150,6 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
11501150
auto isViableForRanking = [this](const BindingSet &bindings) -> bool {
11511151
auto *typeVar = bindings.getTypeVariable();
11521152

1153-
// Type variable representing a base of unresolved member chain should
1154-
// always be considered viable for ranking since it's allow to infer
1155-
// types from transitive protocol requirements.
1156-
if (auto *locator = typeVar->getImpl().getLocator()) {
1157-
if (locator->isLastElement<LocatorPathElt::MemberRefBase>())
1158-
return true;
1159-
}
1160-
11611153
// If type variable is marked as a potential hole there is always going
11621154
// to be at least one binding available for it.
11631155
if (shouldAttemptFixes() && typeVar->getImpl().canBindToHole())
@@ -1180,6 +1172,11 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
11801172
if (!bindings.finalizeKeyPathBindings())
11811173
continue;
11821174

1175+
// Special handling for "leading-dot" unresolved member references,
1176+
// like .foo.
1177+
bindings.inferTransitiveUnresolvedMemberRefBindings();
1178+
bindings.finalizeUnresolvedMemberChainResult();
1179+
11831180
// Before attempting to infer transitive bindings let's check
11841181
// whether there are any viable "direct" bindings associated with
11851182
// current type variable, if there are none - it means that this type
@@ -1194,11 +1191,6 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
11941191

11951192
bindings.inferTransitiveSupertypeBindings();
11961193

1197-
// Special handling for "leading-dot" unresolved member references,
1198-
// like .foo.
1199-
bindings.inferTransitiveUnresolvedMemberRefBindings();
1200-
bindings.finalizeUnresolvedMemberChainResult();
1201-
12021194
bindings.determineLiteralCoverage();
12031195

12041196
if (!bindings.hasViableBindings() && !bindings.isDirectHole())

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
128128
bindings.inferTransitiveKeyPathBindings();
129129
(void) bindings.finalizeKeyPathBindings();
130130

131-
bindings.inferTransitiveSupertypeBindings();
132-
133131
bindings.inferTransitiveUnresolvedMemberRefBindings();
134132
bindings.finalizeUnresolvedMemberChainResult();
135133

134+
bindings.inferTransitiveSupertypeBindings();
135+
136136
bindings.determineLiteralCoverage();
137137

138138
// Inferred a single transitive binding through `$T_float`.

unittests/Sema/SemaFixture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ BindingSet SemaTest::inferBindings(ConstraintSystem &cs,
148148
bindings.inferTransitiveKeyPathBindings();
149149
(void) bindings.finalizeKeyPathBindings();
150150

151-
bindings.inferTransitiveSupertypeBindings();
152-
153151
bindings.inferTransitiveUnresolvedMemberRefBindings();
154152
bindings.finalizeUnresolvedMemberChainResult();
155153

154+
bindings.inferTransitiveSupertypeBindings();
155+
156156
bindings.determineLiteralCoverage();
157157
}
158158

0 commit comments

Comments
 (0)