Skip to content

Commit da58647

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: register loop variables with add().
Change-Id: I321e3ec9b6413028b78bfa36c3022ef70447f745 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109762 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 1390201 commit da58647

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ class FlowAnalysisHelper {
241241
return false;
242242
}
243243

244+
void loopVariable(DeclaredIdentifier loopVariable) {
245+
if (loopVariable != null) {
246+
flow.add(loopVariable.declaredElement, assigned: true);
247+
}
248+
}
249+
244250
void variableDeclarationStatement(VariableDeclarationStatement node) {
245251
var variables = node.variables.variables;
246252
for (var i = 0; i < variables.length; ++i) {

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4568,6 +4568,7 @@ class ResolverVisitor extends ScopedVisitor {
45684568
// cannot be in scope while visiting the iterator.
45694569
//
45704570
iterable?.accept(this);
4571+
_flowAnalysis?.loopVariable(loopVariable);
45714572
loopVariable?.accept(this);
45724573

45734574
_flowAnalysis?.flow?.forEachStatement_bodyBegin(

0 commit comments

Comments
 (0)