Skip to content

Commit 851958e

Browse files
danrubelcommit-bot@chromium.org
authored andcommitted
update NodeBuilder to handle for loop
This updates NodeBUilder to build a node for the identifier in for (int i in <int>[1, 2, 3]) ... Change-Id: Ifcb90f7b1511dc29ecedceb043986f6705bdbe1c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107980 Commit-Queue: Dan Rubel <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 7a73682 commit 851958e

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎pkg/nnbd_migration/lib/src/node_builder.dart‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType> {
130130
return null;
131131
}
132132

133+
@override
134+
DecoratedType visitDeclaredIdentifier(DeclaredIdentifier node) {
135+
node.metadata.accept(this);
136+
DecoratedType type = node.type?.accept(this);
137+
if (node.identifier != null) {
138+
_variables.recordDecoratedElementType(
139+
node.identifier.staticElement, type);
140+
}
141+
return type;
142+
}
143+
133144
@override
134145
DecoratedType visitDefaultFormalParameter(DefaultFormalParameter node) {
135146
var decoratedType = node.parameter.accept(this);

‎pkg/nnbd_migration/test/edge_builder_test.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,15 @@ class C {
993993
decoratedTypeAnnotation('int i').node);
994994
}
995995

996+
test_for_with_declaration() async {
997+
await analyze('''
998+
main() {
999+
for (int i in <int>[1, 2, 3]) { print(i); }
1000+
}
1001+
''');
1002+
// No assertions; just checking that it doesn't crash.
1003+
}
1004+
9961005
test_function_assignment() async {
9971006
await analyze('''
9981007
class C {

0 commit comments

Comments
 (0)