@@ -2660,12 +2660,14 @@ namespace {
2660
2660
2661
2661
// Okay, resolve the pattern.
2662
2662
Pattern *pattern = LabelItem.getPattern ();
2663
- pattern = TypeChecker::resolvePattern (pattern, CS.DC ,
2664
- /* isStmtCondition*/ false );
2665
- if (!pattern) return false ;
2663
+ if (!LabelItem.isPatternResolved ()) {
2664
+ pattern = TypeChecker::resolvePattern (pattern, CS.DC ,
2665
+ /* isStmtCondition*/ false );
2666
+ if (!pattern) return false ;
2666
2667
2667
- // Save that aside while we explore the type.
2668
- LabelItem.setPattern (pattern);
2668
+ // Save that aside while we explore the type.
2669
+ LabelItem.setPattern (pattern, /* resolved=*/ true );
2670
+ }
2669
2671
2670
2672
// Require the pattern to have a particular shape: a number
2671
2673
// of is-patterns applied to an irrefutable pattern.
@@ -2704,7 +2706,7 @@ namespace {
2704
2706
if (!pattern)
2705
2707
return false ;
2706
2708
2707
- LabelItem.setPattern (pattern);
2709
+ LabelItem.setPattern (pattern, /* resolved= */ true );
2708
2710
return LabelItem.isSyntacticallyExhaustive ();
2709
2711
}
2710
2712
@@ -4229,14 +4231,17 @@ bool ConstraintSystem::generateConstraints(
4229
4231
CaseStmt *caseStmt, DeclContext *dc, Type subjectType,
4230
4232
ConstraintLocator *locator) {
4231
4233
// Pre-bind all of the pattern variables within the case.
4232
- bindSwitchCasePatternVars (caseStmt);
4234
+ bindSwitchCasePatternVars (dc, caseStmt);
4233
4235
4234
4236
for (auto &caseLabelItem : caseStmt->getMutableCaseLabelItems ()) {
4235
4237
// Resolve the pattern.
4236
- auto *pattern = TypeChecker::resolvePattern (
4237
- caseLabelItem.getPattern (), dc, /* isStmtCondition=*/ false );
4238
- if (!pattern)
4239
- return true ;
4238
+ auto *pattern = caseLabelItem.getPattern ();
4239
+ if (!caseLabelItem.isPatternResolved ()) {
4240
+ pattern = TypeChecker::resolvePattern (
4241
+ pattern, dc, /* isStmtCondition=*/ false );
4242
+ if (!pattern)
4243
+ return true ;
4244
+ }
4240
4245
4241
4246
// Generate constraints for the pattern, including one-way bindings for
4242
4247
// any variables that show up in this pattern, because those variables
0 commit comments