@@ -1581,9 +1581,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
15811581
15821582 // First pass: check all of the bindings.
15831583 for (auto *caseBlock : make_range (casesBegin, casesEnd)) {
1584- // Bind all of the pattern variables together so we can follow the
1585- // "parent" pointers later on.
1586- bindSwitchCasePatternVars (DC, caseBlock);
1584+ diagnoseCaseVarMutabilityMismatch (DC, caseBlock);
15871585
15881586 auto caseLabelItemArray = caseBlock->getMutableCaseLabelItems ();
15891587 for (auto &labelItem : caseLabelItemArray) {
@@ -3238,7 +3236,8 @@ void swift::checkUnknownAttrRestrictions(
32383236 }
32393237}
32403238
3241- void swift::bindSwitchCasePatternVars (DeclContext *dc, CaseStmt *caseStmt) {
3239+ void swift::diagnoseCaseVarMutabilityMismatch (DeclContext *dc,
3240+ CaseStmt *caseStmt) {
32423241 llvm::SmallDenseMap<Identifier, std::pair<VarDecl *, bool >, 4 > latestVars;
32433242 auto recordVar = [&](Pattern *pattern, VarDecl *var) {
32443243 if (!var->hasName ())
@@ -3248,16 +3247,10 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
32483247 // parent of this new variable.
32493248 auto &entry = latestVars[var->getName ()];
32503249 if (entry.first ) {
3251- assert (!var->getParentVarDecl () ||
3252- var->getParentVarDecl () == entry.first );
3253- var->setParentVarDecl (entry.first );
3254-
32553250 // Check for a mutability mismatch.
3256- if (pattern && entry.second != var->isLet ()) {
3251+ if (entry.second != var->isLet ()) {
32573252 // Find the original declaration.
3258- auto initialCaseVarDecl = entry.first ;
3259- while (auto parentVar = initialCaseVarDecl->getParentVarDecl ())
3260- initialCaseVarDecl = parentVar;
3253+ auto initialCaseVarDecl = entry.first ->getCanonicalVarDecl ();
32613254
32623255 auto diag = var->diagnose (diag::mutability_mismatch_multiple_pattern_list,
32633256 var->isLet (), initialCaseVarDecl->isLet ());
@@ -3268,10 +3261,10 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
32683261 if (VP->getSingleVar () == var)
32693262 foundVP = VP;
32703263 });
3271- if (foundVP)
3264+ if (foundVP) {
32723265 diag.fixItReplace (foundVP->getLoc (),
32733266 initialCaseVarDecl->isLet () ? " let" : " var" );
3274-
3267+ }
32753268 var->setInvalid ();
32763269 initialCaseVarDecl->setInvalid ();
32773270 }
@@ -3283,8 +3276,6 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
32833276 entry.first = var;
32843277 };
32853278
3286- // Wire up the parent var decls for each variable that occurs within
3287- // the patterns of each case item. in source order.
32883279 for (auto &caseItem : caseStmt->getMutableCaseLabelItems ()) {
32893280 // Resolve the pattern.
32903281 auto *pattern = caseItem.getPattern ();
@@ -3300,11 +3291,6 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
33003291 recordVar (pattern, var);
33013292 });
33023293 }
3303-
3304- // Wire up the case body variables to the latest patterns.
3305- for (auto bodyVar : caseStmt->getCaseBodyVariables ()) {
3306- recordVar (nullptr , bodyVar);
3307- }
33083294}
33093295
33103296FuncDecl *TypeChecker::getForEachIteratorNextFunction (
0 commit comments