Merge pull request #85739 from hamishknight/direct-conv

This commit is contained in:
Hamish Knight
2025-12-02 08:40:48 +00:00
committed by GitHub

View File

@@ -9452,17 +9452,17 @@ applySolutionToForEachStmtPreamble(ForEachStmt *stmt,
if (!optPatternType->isEqual(nextResultType)) { if (!optPatternType->isEqual(nextResultType)) {
OpaqueValueExpr *elementExpr = new (ctx) OpaqueValueExpr( OpaqueValueExpr *elementExpr = new (ctx) OpaqueValueExpr(
stmt->getInLoc(), nextResultType->getOptionalObjectType(), stmt->getInLoc(), nextResultType->getOptionalObjectType(),
/*isPlaceholder=*/true); /*isPlaceholder=*/false);
Expr *convertElementExpr = elementExpr; cs.cacheExprTypes(elementExpr);
if (TypeChecker::typeCheckExpression(convertElementExpr, dc,
/*contextualInfo=*/ auto *loc = cs.getConstraintLocator(parsedSequence,
{info.initType, CTP_CoerceOperand}) ConstraintLocator::SequenceElementType);
.isNull()) { auto *convertExpr = solution.coerceToType(elementExpr, info.initType, loc);
if (!convertExpr)
return std::nullopt; return std::nullopt;
}
elementExpr->setIsPlaceholder(false);
stmt->setElementExpr(elementExpr); stmt->setElementExpr(elementExpr);
stmt->setConvertElementExpr(convertElementExpr); stmt->setConvertElementExpr(convertExpr);
} }
// Get the conformance of the sequence type to the Sequence protocol. // Get the conformance of the sequence type to the Sequence protocol.