Infer annotations only for the first VariableDeclarationJudgment of a variable declaration statement.

R=brianwilkerson@google.com, paulberry@google.com

Change-Id: Ic910a2d05be1bf86163f2546dc552100402a0a33
Reviewed-on: https://dart-review.googlesource.com/64668
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart
index 146fec7..d3605d1 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_resolution_kernel_test.dart
@@ -35,11 +35,6 @@
     await super.test_annotation_onFormalParameter_redirectingFactory();
   }
 
-  @failingTest
-  @override
-  test_annotation_onVariableList_topLevelVariable() =>
-      super.test_annotation_onVariableList_topLevelVariable();
-
   @override
   @failingTest
   test_local_type_parameter_reference_function_named_parameter_type() {
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index b7afe74..544f13b 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -1893,17 +1893,25 @@
       }
       push(variable);
     } else {
-      List<VariableDeclaration> variables = popList(count,
-          new List<VariableDeclaration>.filled(count, null, growable: true));
+      List<VariableDeclarationJudgment> variables = popList(
+          count,
+          new List<VariableDeclarationJudgment>.filled(count, null,
+              growable: true));
       constantContext = pop();
       currentLocalVariableType = pop();
       currentLocalVariableModifiers = pop();
       List<Expression> annotations = pop();
       if (annotations != null) {
-        for (VariableDeclaration variable in variables) {
+        bool isFirstVariable = true;
+        for (VariableDeclarationJudgment variable in variables) {
           for (Expression annotation in annotations) {
             variable.addAnnotation(annotation);
           }
+          if (isFirstVariable) {
+            isFirstVariable = false;
+          } else {
+            variable.infersAnnotations = false;
+          }
         }
       }
       push(forest.variablesDeclaration(variables, uri));
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
index b142ae0..090f0d5 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
@@ -3388,6 +3388,12 @@
 
   Object binder;
 
+  /// The same [annotations] list is used for all [VariableDeclarationJudgment]s
+  /// of a variable declaration statement. But we need to perform inference
+  /// only once. So, we set this flag to `false` for the second and subsequent
+  /// judgments.
+  bool infersAnnotations = true;
+
   VariableDeclarationJudgment(String name, this._functionNestingLevel,
       {Expression initializer,
       DartType type,
@@ -3427,7 +3433,9 @@
       ShadowTypeInferrer inferrer,
       Factory<Expression, Statement, Initializer, Type> factory) {
     if (annotationJudgments.isNotEmpty) {
-      inferrer.inferMetadataKeepingHelper(factory, annotationJudgments);
+      if (infersAnnotations) {
+        inferrer.inferMetadataKeepingHelper(factory, annotationJudgments);
+      }
 
       // After the inference was done on the annotations, we may clone them for
       // this instance of VariableDeclaration in order to avoid having the same