Read VariableDeclaration type during checking for implicitly typed.

R=brianwilkerson@google.com

Change-Id: Ide32d69775df15aa3524893734a11dc7299bdc72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101221
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/linked_unit_context.dart b/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
index a1a58c1..b32ee0c 100644
--- a/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
+++ b/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
@@ -743,6 +743,7 @@
       return node.type == null;
     } else if (node is VariableDeclaration) {
       VariableDeclarationList parent = node.parent;
+      LazyVariableDeclarationList.readTypeNode(_astReader, parent);
       return parent.type == null;
     }
     return false;
diff --git a/pkg/analyzer/test/src/diagnostics/top_level_instance_getter_test.dart b/pkg/analyzer/test/src/diagnostics/top_level_instance_getter_test.dart
index 8427700..2a28469 100644
--- a/pkg/analyzer/test/src/diagnostics/top_level_instance_getter_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/top_level_instance_getter_test.dart
@@ -52,6 +52,19 @@
     expect(b.variables.variables[0].declaredElement.type.toString(), 'int');
   }
 
+  test_field_imported() async {
+    newFile('/test/lib/a.dart', content: '''
+class A {
+  int f;
+}
+''');
+    await assertNoErrorsInCode('''
+import 'a.dart';
+var b = new A().f;
+''');
+    assertElementTypeString(findElement.topVar('b').type, 'int');
+  }
+
   test_field_prefixedIdentifier() async {
     await assertNoErrorsInCode('''
 class A {