Skip to content

Commit fc74e99

Browse files
committed
Fix test failure
1 parent 004299a commit fc74e99

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

lib/Sema/CSGen.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,7 +4412,8 @@ generateForEachStmtConstraints(ConstraintSystem &cs, DeclContext *dc,
44124412

44134413
static llvm::Optional<SequenceIterationInfo>
44144414
generateForEachStmtConstraints(ConstraintSystem &cs, DeclContext *dc,
4415-
ForEachStmt *stmt, Type patternType) {
4415+
ForEachStmt *stmt, Pattern *typeCheckedPattern,
4416+
bool shouldBindPatternVarsOneWay) {
44164417
ASTContext &ctx = cs.getASTContext();
44174418
auto *forEachExpr = stmt->getParsedSequence();
44184419
bool isAsync = stmt->getAwaitLoc().isValid();
@@ -4537,7 +4538,12 @@ generateForEachStmtConstraints(ConstraintSystem &cs, DeclContext *dc,
45374538
cs.setTargetFor(sequenceIterationInfo.nextCall, nextTarget);
45384539
}
45394540

4540-
Type initType = patternType;
4541+
// Create a type variable for a named pattern
4542+
Type initType =
4543+
cs.generateConstraints(typeCheckedPattern, elementLocator,
4544+
shouldBindPatternVarsOneWay, nullptr, 0);
4545+
if (!initType)
4546+
return llvm::None;
45414547

45424548
// Add a conversion constraint between the element type of the sequence
45434549
// and the type of the element pattern.
@@ -4567,12 +4573,12 @@ generateForEachStmtConstraints(ConstraintSystem &cs,
45674573
SyntacticElementTarget target) {
45684574
ASTContext &ctx = cs.getASTContext();
45694575
ForEachStmt *stmt = target.getAsForEachStmt();
4570-
auto *forEachExpr = stmt->getParsedSequence();
4576+
auto *sequenceExpr = stmt->getParsedSequence();
45714577
auto *dc = target.getDeclContext();
45724578

45734579
// Collect constraints from the element pattern.
45744580
auto elementLocator = cs.getConstraintLocator(
4575-
forEachExpr, ConstraintLocator::SequenceElementType);
4581+
sequenceExpr, ConstraintLocator::SequenceElementType);
45764582

45774583
Pattern *pattern = TypeChecker::resolvePattern(stmt->getPattern(), dc,
45784584
/*isStmtCondition*/ false);
@@ -4585,23 +4591,24 @@ generateForEachStmtConstraints(ConstraintSystem &cs,
45854591
if (TypeChecker::typeCheckPattern(contextualPattern)->hasError()) {
45864592
return llvm::None;
45874593
}
4588-
// Create a type variable for a named pattern
4589-
Type patternType =
4590-
cs.generateConstraints(pattern, elementLocator,
4591-
target.shouldBindPatternVarsOneWay(), nullptr, 0);
4592-
if (!patternType)
4593-
return llvm::None;
45944594

45954595
auto forEachLocator = cs.getConstraintLocator(stmt);
45964596

4597-
if (isa<PackExpansionExpr>(forEachExpr)) {
4597+
if (isa<PackExpansionExpr>(sequenceExpr)) {
45984598
if (!ctx.LangOpts.hasFeature(Feature::PackIteration)) {
45994599
if (!cs.shouldAttemptFixes())
46004600
return llvm::None;
46014601

46024602
cs.recordFix(AllowInvalidPackExpansion::create(cs, forEachLocator));
46034603
}
4604-
auto *expansion = cast<PackExpansionExpr>(forEachExpr);
4604+
auto *expansion = cast<PackExpansionExpr>(sequenceExpr);
4605+
4606+
// Create a type variable for a named pattern
4607+
Type patternType = cs.generateConstraints(
4608+
pattern, elementLocator, target.shouldBindPatternVarsOneWay(), nullptr,
4609+
0);
4610+
if (!patternType)
4611+
return llvm::None;
46054612

46064613
auto packIterationInfo =
46074614
generateForEachStmtConstraints(cs, dc, expansion, patternType);
@@ -4611,8 +4618,8 @@ generateForEachStmtConstraints(ConstraintSystem &cs,
46114618

46124619
target.getForEachStmtInfo() = *packIterationInfo;
46134620
} else {
4614-
auto sequenceIterationInfo =
4615-
generateForEachStmtConstraints(cs, dc, stmt, patternType);
4621+
auto sequenceIterationInfo = generateForEachStmtConstraints(
4622+
cs, dc, stmt, pattern, target.shouldBindPatternVarsOneWay());
46164623
if (!sequenceIterationInfo) {
46174624
return llvm::None;
46184625
}

0 commit comments

Comments
 (0)