@@ -259,17 +259,13 @@ class BuilderClosureVisitor
259
259
260
260
// Generate constraints for the initialization.
261
261
auto target = SolutionApplicationTarget::forInitialization (
262
- patternBinding->getInit (index), dc, patternType, pattern);
262
+ patternBinding->getInit (index), dc, patternType, pattern,
263
+ /* bindPatternVarsOneWay=*/ true );
263
264
if (cs->generateConstraints (target, FreeTypeVariableBinding::Disallow))
264
265
continue ;
265
266
266
267
// Keep track of this binding entry.
267
268
applied.patternBindingEntries .insert ({{patternBinding, index}, target});
268
-
269
- // Bind the variables that occur in the pattern to the corresponding
270
- // type entry for the pattern itself.
271
- cs->bindVariablesInPattern (
272
- pattern, cs->getConstraintLocator (target.getAsExpr ()));
273
269
}
274
270
}
275
271
@@ -380,10 +376,6 @@ class BuilderClosureVisitor
380
376
static bool isBuildableIfChainRecursive (IfStmt *ifStmt,
381
377
unsigned &numPayloads,
382
378
bool &isOptional) {
383
- // Check whether we can handle the conditional.
384
- if (!ConstraintSystem::canGenerateConstraints (ifStmt->getCond ()))
385
- return false ;
386
-
387
379
// The 'then' clause contributes a payload.
388
380
numPayloads++;
389
381
@@ -451,6 +443,14 @@ class BuilderClosureVisitor
451
443
unsigned numPayloads, bool isOptional,
452
444
bool isTopLevel = false ) {
453
445
assert (payloadIndex < numPayloads);
446
+
447
+ // First generate constraints for the conditions. This can introduce
448
+ // variable bindings that will be used within the "then" branch.
449
+ if (cs && cs->generateConstraints (ifStmt->getCond (), dc)) {
450
+ hadError = true ;
451
+ return nullptr ;
452
+ }
453
+
454
454
// Make sure we recursively visit both sides even if we're not
455
455
// building expressions.
456
456
@@ -507,12 +507,6 @@ class BuilderClosureVisitor
507
507
payloadIndex + 1 , numPayloads, isOptional);
508
508
}
509
509
510
- // Generate constraints for the conditions.
511
- if (cs->generateConstraints (ifStmt->getCond (), dc)) {
512
- hadError = true ;
513
- return nullptr ;
514
- }
515
-
516
510
// The operand should have optional type if we had optional results,
517
511
// so we just need to call `buildIf` now, since we're at the top level.
518
512
if (isOptional && isTopLevel) {
@@ -945,8 +939,16 @@ class BuilderClosureRewriter
945
939
continue ;
946
940
}
947
941
948
- case StmtConditionElement::CK_PatternBinding:
949
- llvm_unreachable (" unhandled statement condition" );
942
+ case StmtConditionElement::CK_PatternBinding: {
943
+ ConstraintSystem &cs = solution.getConstraintSystem ();
944
+ auto target = *cs.getStmtConditionTarget (&condElement);
945
+ auto resolvedTarget = rewriteTarget (target);
946
+ if (resolvedTarget) {
947
+ condElement.setInitializer (resolvedTarget->getAsExpr ());
948
+ condElement.setPattern (resolvedTarget->getInitializationPattern ());
949
+ }
950
+ continue ;
951
+ }
950
952
}
951
953
}
952
954
ifStmt->setCond (condition);
0 commit comments