Skip to content

Commit 654ec0d

Browse files
committed
[ConstraintSystem] NFC: Modernize SK_NonDefaultLiteral inference
1 parent 03e0c4a commit 654ec0d

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,35 +167,32 @@ void ConstraintSystem::assignFixedType(TypeVariableType *typeVar, Type type,
167167
if (!type->isTypeVariableOrMember()) {
168168
// If this type variable represents a literal, check whether we picked the
169169
// default literal type. First, find the corresponding protocol.
170-
ProtocolDecl *literalProtocol = nullptr;
170+
//
171171
// If we have the constraint graph, we can check all type variables in
172172
// the equivalence class. This is the More Correct path.
173173
// FIXME: Eliminate the less-correct path.
174174
auto typeVarRep = getRepresentative(typeVar);
175-
for (auto tv : CG[typeVarRep].getEquivalenceClass()) {
175+
for (auto *tv : CG[typeVarRep].getEquivalenceClass()) {
176176
auto locator = tv->getImpl().getLocator();
177-
if (!locator || !locator->getPath().empty())
178-
continue;
177+
if (!(locator && (locator->directlyAt<CollectionExpr>() ||
178+
locator->directlyAt<LiteralExpr>())))
179+
continue;
179180

180-
auto *anchor = getAsExpr(locator->getAnchor());
181-
if (!anchor)
181+
auto *literalProtocol = TypeChecker::getLiteralProtocol(
182+
getASTContext(), castToExpr(locator->getAnchor()));
183+
if (!literalProtocol)
182184
continue;
183185

184-
literalProtocol =
185-
TypeChecker::getLiteralProtocol(getASTContext(), anchor);
186-
if (literalProtocol)
187-
break;
188-
}
189-
190-
// If the protocol has a default type, check it.
191-
if (literalProtocol) {
186+
// If the protocol has a default type, check it.
192187
if (auto defaultType = TypeChecker::getDefaultType(literalProtocol, DC)) {
193188
// Check whether the nominal types match. This makes sure that we
194189
// properly handle Array vs. Array<T>.
195190
if (defaultType->getAnyNominal() != type->getAnyNominal()) {
196191
increaseScore(SK_NonDefaultLiteral);
197192
}
198193
}
194+
195+
break;
199196
}
200197
}
201198

0 commit comments

Comments
 (0)