@@ -1581,9 +1581,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1581
1581
1582
1582
// First pass: check all of the bindings.
1583
1583
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);
1587
1585
1588
1586
auto caseLabelItemArray = caseBlock->getMutableCaseLabelItems ();
1589
1587
for (auto &labelItem : caseLabelItemArray) {
@@ -3238,7 +3236,8 @@ void swift::checkUnknownAttrRestrictions(
3238
3236
}
3239
3237
}
3240
3238
3241
- void swift::bindSwitchCasePatternVars (DeclContext *dc, CaseStmt *caseStmt) {
3239
+ void swift::diagnoseCaseVarMutabilityMismatch (DeclContext *dc,
3240
+ CaseStmt *caseStmt) {
3242
3241
llvm::SmallDenseMap<Identifier, std::pair<VarDecl *, bool >, 4 > latestVars;
3243
3242
auto recordVar = [&](Pattern *pattern, VarDecl *var) {
3244
3243
if (!var->hasName ())
@@ -3248,16 +3247,10 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
3248
3247
// parent of this new variable.
3249
3248
auto &entry = latestVars[var->getName ()];
3250
3249
if (entry.first ) {
3251
- assert (!var->getParentVarDecl () ||
3252
- var->getParentVarDecl () == entry.first );
3253
- var->setParentVarDecl (entry.first );
3254
-
3255
3250
// Check for a mutability mismatch.
3256
- if (pattern && entry.second != var->isLet ()) {
3251
+ if (entry.second != var->isLet ()) {
3257
3252
// Find the original declaration.
3258
- auto initialCaseVarDecl = entry.first ;
3259
- while (auto parentVar = initialCaseVarDecl->getParentVarDecl ())
3260
- initialCaseVarDecl = parentVar;
3253
+ auto initialCaseVarDecl = entry.first ->getCanonicalVarDecl ();
3261
3254
3262
3255
auto diag = var->diagnose (diag::mutability_mismatch_multiple_pattern_list,
3263
3256
var->isLet (), initialCaseVarDecl->isLet ());
@@ -3268,10 +3261,10 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
3268
3261
if (VP->getSingleVar () == var)
3269
3262
foundVP = VP;
3270
3263
});
3271
- if (foundVP)
3264
+ if (foundVP) {
3272
3265
diag.fixItReplace (foundVP->getLoc (),
3273
3266
initialCaseVarDecl->isLet () ? " let" : " var" );
3274
-
3267
+ }
3275
3268
var->setInvalid ();
3276
3269
initialCaseVarDecl->setInvalid ();
3277
3270
}
@@ -3283,8 +3276,6 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
3283
3276
entry.first = var;
3284
3277
};
3285
3278
3286
- // Wire up the parent var decls for each variable that occurs within
3287
- // the patterns of each case item. in source order.
3288
3279
for (auto &caseItem : caseStmt->getMutableCaseLabelItems ()) {
3289
3280
// Resolve the pattern.
3290
3281
auto *pattern = caseItem.getPattern ();
@@ -3300,11 +3291,6 @@ void swift::bindSwitchCasePatternVars(DeclContext *dc, CaseStmt *caseStmt) {
3300
3291
recordVar (pattern, var);
3301
3292
});
3302
3293
}
3303
-
3304
- // Wire up the case body variables to the latest patterns.
3305
- for (auto bodyVar : caseStmt->getCaseBodyVariables ()) {
3306
- recordVar (nullptr , bodyVar);
3307
- }
3308
3294
}
3309
3295
3310
3296
FuncDecl *TypeChecker::getForEachIteratorNextFunction (
0 commit comments