@@ -167,35 +167,32 @@ void ConstraintSystem::assignFixedType(TypeVariableType *typeVar, Type type,
167
167
if (!type->isTypeVariableOrMember ()) {
168
168
// If this type variable represents a literal, check whether we picked the
169
169
// default literal type. First, find the corresponding protocol.
170
- ProtocolDecl *literalProtocol = nullptr ;
170
+ //
171
171
// If we have the constraint graph, we can check all type variables in
172
172
// the equivalence class. This is the More Correct path.
173
173
// FIXME: Eliminate the less-correct path.
174
174
auto typeVarRep = getRepresentative (typeVar);
175
- for (auto tv : CG[typeVarRep].getEquivalenceClass ()) {
175
+ for (auto * tv : CG[typeVarRep].getEquivalenceClass ()) {
176
176
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 ;
179
180
180
- auto *anchor = getAsExpr (locator->getAnchor ());
181
- if (!anchor)
181
+ auto *literalProtocol = TypeChecker::getLiteralProtocol (
182
+ getASTContext (), castToExpr (locator->getAnchor ()));
183
+ if (!literalProtocol)
182
184
continue ;
183
185
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.
192
187
if (auto defaultType = TypeChecker::getDefaultType (literalProtocol, DC)) {
193
188
// Check whether the nominal types match. This makes sure that we
194
189
// properly handle Array vs. Array<T>.
195
190
if (defaultType->getAnyNominal () != type->getAnyNominal ()) {
196
191
increaseScore (SK_NonDefaultLiteral);
197
192
}
198
193
}
194
+
195
+ break ;
199
196
}
200
197
}
201
198
0 commit comments