@@ -7971,10 +7971,12 @@ static Optional<SolutionApplicationTarget> applySolutionToForEachStmt(
7971
7971
auto stmt = forEachStmtInfo.stmt ;
7972
7972
auto sequenceProto = TypeChecker::getProtocol (
7973
7973
cs.getASTContext (), stmt->getForLoc (), KnownProtocolKind::Sequence);
7974
- auto contextualLocator = cs.getConstraintLocator (
7975
- target.getAsExpr (), LocatorPathElt::ContextualType ());
7976
- auto sequenceConformance = solution.resolveConformance (
7977
- contextualLocator, sequenceProto);
7974
+ auto contextualLocator = solution.getConstraintLocator (
7975
+ target.getAsExpr (),
7976
+ {LocatorPathElt::ContextualType (),
7977
+ LocatorPathElt::ConformanceRequirement (sequenceProto)});
7978
+ auto sequenceConformance =
7979
+ solution.resolveConformance (contextualLocator, sequenceProto);
7978
7980
assert (!sequenceConformance.isInvalid () &&
7979
7981
" Couldn't find sequence conformance" );
7980
7982
@@ -8385,32 +8387,30 @@ Expr *Solution::coerceToType(Expr *expr, Type toType,
8385
8387
8386
8388
ProtocolConformanceRef Solution::resolveConformance (
8387
8389
ConstraintLocator *locator, ProtocolDecl *proto) {
8388
- for (const auto &conformance : Conformances) {
8389
- if (conformance.first != locator)
8390
- continue ;
8391
- if (conformance.second .getRequirement () != proto)
8392
- continue ;
8393
-
8394
- // If the conformance doesn't require substitution, return it immediately.
8395
- auto conformanceRef = conformance.second ;
8396
- if (conformanceRef.isAbstract ())
8397
- return conformanceRef;
8398
-
8399
- auto concrete = conformanceRef.getConcrete ();
8400
- auto conformingType = concrete->getType ();
8401
- if (!conformingType->hasTypeVariable ())
8402
- return conformanceRef;
8403
-
8404
- // Substitute into the conformance type, then look for a conformance
8405
- // again.
8406
- // FIXME: Should be able to perform the substitution using the Solution
8407
- // itself rather than another conforms-to-protocol check.
8408
- Type substConformingType = simplifyType (conformingType);
8409
- return TypeChecker::conformsToProtocol (
8410
- substConformingType, proto, constraintSystem->DC );
8411
- }
8412
-
8413
- return ProtocolConformanceRef::forInvalid ();
8390
+ auto conformance = llvm::find_if (Conformances, [&locator](const auto &elt) {
8391
+ return elt.first == locator;
8392
+ });
8393
+
8394
+ if (conformance == Conformances.end ())
8395
+ return ProtocolConformanceRef::forInvalid ();
8396
+
8397
+ // If the conformance doesn't require substitution, return it immediately.
8398
+ auto conformanceRef = conformance->second ;
8399
+ if (conformanceRef.isAbstract ())
8400
+ return conformanceRef;
8401
+
8402
+ auto concrete = conformanceRef.getConcrete ();
8403
+ auto conformingType = concrete->getType ();
8404
+ if (!conformingType->hasTypeVariable ())
8405
+ return conformanceRef;
8406
+
8407
+ // Substitute into the conformance type, then look for a conformance
8408
+ // again.
8409
+ // FIXME: Should be able to perform the substitution using the Solution
8410
+ // itself rather than another conforms-to-protocol check.
8411
+ Type substConformingType = simplifyType (conformingType);
8412
+ return TypeChecker::conformsToProtocol (substConformingType, proto,
8413
+ constraintSystem->DC );
8414
8414
}
8415
8415
8416
8416
bool Solution::hasType (ASTNode node) const {
0 commit comments