[fasta] Transform set literals in annotations.

Change-Id: I23e60cb85e1df728fc3be3b38be43e31a1795d1d
Reviewed-on: https://dart-review.googlesource.com/c/93941
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
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 83de3c0..d2dd71e 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -447,6 +447,20 @@
     return new JumpTarget(kind, functionNestingLevel, member, charOffset);
   }
 
+  void inferAnnotations(List<Expression> annotations) {
+    if (annotations != null) {
+      _typeInferrer?.inferMetadata(this, annotations);
+      if (transformSetLiterals) {
+        library.loader.setLiteralTransformer ??=
+            new SetLiteralTransformer(library.loader);
+        for (int i = 0; i < annotations.length; i++) {
+          annotations[i] =
+              annotations[i].accept(library.loader.setLiteralTransformer);
+        }
+      }
+    }
+  }
+
   @override
   void beginMetadata(Token token) {
     debugEvent("beginMetadata");
@@ -574,7 +588,7 @@
     }
     List<Expression> annotations = pop();
     if (annotations != null) {
-      _typeInferrer?.inferMetadata(this, annotations);
+      inferAnnotations(annotations);
       Field field = fields.first.target;
       // The first (and often only field) will not get a clone.
       for (int i = 0; i < annotations.length; i++) {
@@ -878,7 +892,7 @@
       }
     }
     Member target = builder.target;
-    _typeInferrer?.inferMetadata(this, annotations);
+    inferAnnotations(annotations);
     for (Expression annotation in annotations ?? const []) {
       target.addAnnotation(annotation);
     }
@@ -991,15 +1005,14 @@
 
     if (variablesWithMetadata != null) {
       for (int i = 0; i < variablesWithMetadata.length; i++) {
-        _typeInferrer?.inferMetadata(
-            this, variablesWithMetadata[i].annotations);
+        inferAnnotations(variablesWithMetadata[i].annotations);
       }
     }
     if (multiVariablesWithMetadata != null) {
       for (int i = 0; i < multiVariablesWithMetadata.length; i++) {
         List<VariableDeclaration> variables = multiVariablesWithMetadata[i];
         List<Expression> annotations = variables.first.annotations;
-        _typeInferrer?.inferMetadata(this, annotations);
+        inferAnnotations(annotations);
         for (int i = 1; i < variables.length; i++) {
           cloner ??= new CloneVisitor();
           VariableDeclaration variable = variables[i];
@@ -1014,7 +1027,7 @@
   @override
   List<Expression> finishMetadata(TreeNode parent) {
     List<Expression> expressions = pop();
-    _typeInferrer?.inferMetadata(this, expressions);
+    inferAnnotations(expressions);
 
     // The invocation of [resolveRedirectingFactoryTargets] below may change the
     // root nodes of the annotation expressions.  We need to have a parent of
@@ -2809,7 +2822,7 @@
     }
     if (annotations != null) {
       if (functionNestingLevel == 0) {
-        _typeInferrer?.inferMetadata(this, annotations);
+        inferAnnotations(annotations);
       }
       for (Expression annotation in annotations) {
         variable.addAnnotation(annotation);
@@ -4409,7 +4422,7 @@
     KernelTypeVariableBuilder variable = new KernelTypeVariableBuilder(
         name.name, library, name.charOffset, null);
     if (annotations != null) {
-      _typeInferrer?.inferMetadata(this, annotations);
+      inferAnnotations(annotations);
       for (Expression annotation in annotations) {
         variable.parameter.addAnnotation(annotation);
       }
diff --git a/tests/language_2/set_literals_in_annotations.dart b/tests/language_2/set_literals_in_annotations.dart
new file mode 100644
index 0000000..5dca8c3
--- /dev/null
+++ b/tests/language_2/set_literals_in_annotations.dart
@@ -0,0 +1,38 @@
+// Copyright (c) 2019, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+@Meta({})
+import 'dart:core';
+
+@Meta({})
+void f(@Meta({}) int foo) {}
+
+@Meta({})
+class A<@Meta({}) T> {
+  @Meta({})
+  String x, y;
+
+  @Meta({})
+  A();
+
+  @Meta({})
+  void m() {
+    @Meta({})
+    int z;
+  }
+}
+
+@Meta({})
+enum E {
+  @Meta({})
+  v
+}
+
+class Meta {
+  final Set<int> value;
+
+  const Meta(this.value);
+}
+
+main() {}