Migration: support references to local variables.

Change-Id: I43c4e2882c003b9cb219406c2aaac507b7f63979
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104802
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/nullability/graph_builder.dart b/pkg/analysis_server/lib/src/nullability/graph_builder.dart
index 1cf5c85..0c3cf07 100644
--- a/pkg/analysis_server/lib/src/nullability/graph_builder.dart
+++ b/pkg/analysis_server/lib/src/nullability/graph_builder.dart
@@ -391,7 +391,8 @@
   @override
   DecoratedType visitSimpleIdentifier(SimpleIdentifier node) {
     var staticElement = node.staticElement;
-    if (staticElement is ParameterElement) {
+    if (staticElement is ParameterElement ||
+        staticElement is LocalVariableElement) {
       return getOrComputeElementType(staticElement);
     } else if (staticElement is ClassElement) {
       return _nonNullableTypeType;
diff --git a/pkg/analysis_server/test/src/nullability/migration_visitor_test.dart b/pkg/analysis_server/test/src/nullability/migration_visitor_test.dart
index 5851f82..f83303d 100644
--- a/pkg/analysis_server/test/src/nullability/migration_visitor_test.dart
+++ b/pkg/analysis_server/test/src/nullability/migration_visitor_test.dart
@@ -765,6 +765,19 @@
         contextNode: decoratedTypeAnnotation('int').node);
   }
 
+  test_simpleIdentifier_local() async {
+    await analyze('''
+main() {
+  int i = 0;
+  int j = i;
+}
+''');
+
+    assertEdge(decoratedTypeAnnotation('int i').node,
+        decoratedTypeAnnotation('int j').node,
+        hard: true);
+  }
+
   test_soft_edge_for_non_variable_reference() async {
     // Edges originating in things other than variable references should be
     // soft.
diff --git a/pkg/analysis_server/test/src/nullability/provisional_api_test.dart b/pkg/analysis_server/test/src/nullability/provisional_api_test.dart
index 47140d6..0a6f48d 100644
--- a/pkg/analysis_server/test/src/nullability/provisional_api_test.dart
+++ b/pkg/analysis_server/test/src/nullability/provisional_api_test.dart
@@ -306,6 +306,30 @@
     await _checkSingleFileChanges(content, expected);
   }
 
+  test_data_flow_local_reference() async {
+    var content = '''
+void f(int i) {}
+void g(int i) {
+  int j = i;
+  f(i);
+}
+main() {
+  g(null);
+}
+''';
+    var expected = '''
+void f(int? i) {}
+void g(int? i) {
+  int? j = i;
+  f(i);
+}
+main() {
+  g(null);
+}
+''';
+    await _checkSingleFileChanges(content, expected);
+  }
+
   test_data_flow_outward() async {
     var content = '''
 int f(int i) => null;