mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Support for fallthrough into cases with pattern variables.
This commit is contained in:
@@ -2355,6 +2355,29 @@ public:
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// A fallthrough dest case's bound variable means the source case's
|
||||
// var of the same name is read.
|
||||
if (auto *fallthroughStmt = dyn_cast<FallthroughStmt>(S)) {
|
||||
if (auto *sourceCase = fallthroughStmt->getFallthroughSource()) {
|
||||
SmallVector<VarDecl *, 4> sourceVars;
|
||||
auto sourcePattern = sourceCase->getCaseLabelItems()[0].getPattern();
|
||||
sourcePattern->collectVariables(sourceVars);
|
||||
|
||||
auto destCase = fallthroughStmt->getFallthroughDest();
|
||||
auto destPattern = destCase->getCaseLabelItems()[0].getPattern();
|
||||
destPattern->forEachVariable([&](VarDecl *V) {
|
||||
if (!V->hasName())
|
||||
return;
|
||||
for (auto *var : sourceVars) {
|
||||
if (var->hasName() && var->getName() == V->getName()) {
|
||||
VarDecls[var] |= RK_Read;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { true, S };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user