Skip to content

Commit f7ddfdf

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: don't forget to visit variable initializers in NodeBuilder.
Also visit any annotations present in a variable declaration (we can't yet test this part well but we might as well add the proper code now). Change-Id: I1c8f19c9516d1e0f17f024fa136bd7d331ed8ae1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107643 Reviewed-by: Dan Rubel <danrubel@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent a39e4fa commit f7ddfdf

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/nnbd_migration/lib/src/node_builder.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,12 @@ $stackTrace''');
341341

342342
@override
343343
DecoratedType visitVariableDeclarationList(VariableDeclarationList node) {
344+
node.metadata.accept(this);
344345
var type = decorateType(node.type, node);
345346
for (var variable in node.variables) {
347+
variable.metadata.accept(this);
346348
_variables.recordDecoratedElementType(variable.declaredElement, type);
349+
variable.initializer?.accept(this);
347350
}
348351
return null;
349352
}

pkg/nnbd_migration/test/node_builder_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,17 @@ main() {
694694
expect(decoratedType.node, TypeMatcher<NullabilityNodeMutable>());
695695
}
696696

697+
test_variableDeclaration_visit_initializer() async {
698+
await analyze('''
699+
class C<T> {}
700+
void f(C<dynamic> c) {
701+
var x = c as C<int>;
702+
}
703+
''');
704+
var decoratedType = decoratedTypeAnnotation('int');
705+
expect(decoratedType.node, TypeMatcher<NullabilityNodeMutable>());
706+
}
707+
697708
test_void_type() async {
698709
await analyze('''
699710
void f() {}

0 commit comments

Comments
 (0)