@@ -529,6 +529,9 @@ class SyntacticElementConstraintGenerator
529529 void visitCaseItem (CaseLabelItem *caseItem, ContextualTypeInfo contextInfo) {
530530 assert (contextInfo.purpose == CTP_CaseStmt);
531531
532+ auto *DC = context.getAsDeclContext ();
533+ auto &ctx = DC->getASTContext ();
534+
532535 // Resolve the pattern.
533536 auto *pattern = caseItem->getPattern ();
534537 if (!caseItem->isPatternResolved ()) {
@@ -554,11 +557,15 @@ class SyntacticElementConstraintGenerator
554557
555558 // Generate constraints for `where` clause (if any).
556559 if (guardExpr) {
557- guardExpr = cs.generateConstraints (guardExpr, context.getAsDeclContext ());
558- if (!guardExpr) {
560+ SolutionApplicationTarget guardTarget (
561+ guardExpr, DC, CTP_Condition, ctx.getBoolType (), /* discarded*/ false );
562+
563+ if (cs.generateConstraints (guardTarget)) {
559564 hadError = true ;
560565 return ;
561566 }
567+ guardExpr = guardTarget.getAsExpr ();
568+ cs.setSolutionApplicationTarget (guardExpr, guardTarget);
562569 }
563570
564571 // Save information about case item so it could be referenced during
@@ -580,7 +587,7 @@ class SyntacticElementConstraintGenerator
580587 forEachStmt, context.getAsDeclContext (),
581588 /* bindTypeVarsOneWay=*/ false );
582589
583- if (cs.generateConstraints (target, FreeTypeVariableBinding::Disallow )) {
590+ if (cs.generateConstraints (target)) {
584591 hadError = true ;
585592 return ;
586593 }
@@ -734,7 +741,7 @@ class SyntacticElementConstraintGenerator
734741 if (isPlaceholderVar (patternBinding))
735742 return ;
736743
737- if (cs.generateConstraints (*target, FreeTypeVariableBinding::Disallow )) {
744+ if (cs.generateConstraints (*target)) {
738745 hadError = true ;
739746 return ;
740747 }
@@ -1128,7 +1135,7 @@ class SyntacticElementConstraintGenerator
11281135 contextualResultInfo.getType (),
11291136 /* isDiscarded=*/ false );
11301137
1131- if (cs.generateConstraints (target, FreeTypeVariableBinding::Disallow )) {
1138+ if (cs.generateConstraints (target)) {
11321139 hadError = true ;
11331140 return ;
11341141 }
@@ -1430,7 +1437,7 @@ ConstraintSystem::simplifySyntacticElementConstraint(
14301437 contextInfo.purpose , contextInfo.getType (),
14311438 contextualTypeLoc, isDiscarded);
14321439
1433- if (generateConstraints (target, FreeTypeVariableBinding::Disallow ))
1440+ if (generateConstraints (target))
14341441 return SolutionKind::Error;
14351442
14361443 setSolutionApplicationTarget (expr, target);
0 commit comments