Version 2.16.0-8.0.dev
Merge commit '2b9645318c99421ebf970479a5817baa62340d9a' into 'dev'
diff --git a/pkg/nnbd_migration/lib/src/node_builder.dart b/pkg/nnbd_migration/lib/src/node_builder.dart
index 653d36b..2dad8d1 100644
--- a/pkg/nnbd_migration/lib/src/node_builder.dart
+++ b/pkg/nnbd_migration/lib/src/node_builder.dart
@@ -660,7 +660,7 @@
DecoratedType? visitVariableDeclarationList(VariableDeclarationList node) {
node.metadata.accept(this);
var typeAnnotation = node.type;
- var type = _pushNullabilityNodeTarget(
+ var declaredType = _pushNullabilityNodeTarget(
NullabilityNodeTarget.element(
node.variables.first.declaredElement!, _getLineInfo),
() => typeAnnotation?.accept(this));
@@ -671,9 +671,11 @@
if (hint != null && hint.kind == HintCommentKind.lateFinal) {
_variables!.recordLateHint(source, node, hint);
}
+ var parent = node.parent;
for (var variable in node.variables) {
variable.metadata.accept(this);
var declaredElement = variable.declaredElement;
+ var type = declaredType;
if (type == null) {
var target =
NullabilityNodeTarget.element(declaredElement!, _getLineInfo);
@@ -683,11 +685,11 @@
}
_variables!.recordDecoratedElementType(declaredElement, type);
variable.initializer?.accept(this);
- }
- var parent = node.parent;
- if (parent is FieldDeclaration) {
- if (_hasAngularChildAnnotation(parent.metadata)) {
- _graph.makeNullable(type!.node!, AngularAnnotationOrigin(source, node));
+ if (parent is FieldDeclaration) {
+ if (_hasAngularChildAnnotation(parent.metadata)) {
+ _graph.makeNullable(
+ type.node!, AngularAnnotationOrigin(source, node));
+ }
}
}
return null;
diff --git a/pkg/nnbd_migration/test/api_test.dart b/pkg/nnbd_migration/test/api_test.dart
index de7d447..69a8936 100644
--- a/pkg/nnbd_migration/test/api_test.dart
+++ b/pkg/nnbd_migration/test/api_test.dart
@@ -8927,6 +8927,31 @@
await _checkSingleFileChanges(content, expected);
}
+ Future<void> test_var_with_different_types() async {
+ // Based on https://github.com/dart-lang/sdk/issues/47669
+ var content = '''
+class C<T> {
+ T m() => throw 'foo';
+}
+f(bool b, List<C<int>> cs) {
+ var x = !b,
+ y = cs.first,
+ z = y.m();
+}
+''';
+ var expected = '''
+class C<T> {
+ T m() => throw 'foo';
+}
+f(bool b, List<C<int>> cs) {
+ var x = !b,
+ y = cs.first,
+ z = y.m();
+}
+''';
+ await _checkSingleFileChanges(content, expected);
+ }
+
Future<void> test_weak_if_visit_weak_subexpression() async {
var content = '''
int f(int x, int/*?*/ y) {
diff --git a/tools/VERSION b/tools/VERSION
index b8d6a86..78db584 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 16
PATCH 0
-PRERELEASE 7
+PRERELEASE 8
PRERELEASE_PATCH 0
\ No newline at end of file