[fasta] Transform set literals in initializers and default values.

The set literal desugaring was missing set literals in constructor
initializers and parameter default values. Furthermore, it assumed
that a constructor that contained a set literal had a body.

Fixes https://github.com/dart-lang/sdk/issues/35989

Change-Id: I42c77b96bbe751ee6f7c7ba7921e9b9df24c16e9
Reviewed-on: https://dart-review.googlesource.com/c/93660
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Peter von der Ahé <ahe@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 d526ee2..83de3c0 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -741,6 +741,11 @@
           realParameter.initializer = initializer..parent = realParameter;
           _typeInferrer?.inferParameterInitializer(
               this, initializer, realParameter.type);
+          if (transformSetLiterals) {
+            library.loader.setLiteralTransformer ??=
+                new SetLiteralTransformer(library.loader);
+            realParameter.accept(library.loader.setLiteralTransformer);
+          }
         }
       }
     }
@@ -751,7 +756,7 @@
     if (transformSetLiterals) {
       library.loader.setLiteralTransformer ??=
           new SetLiteralTransformer(library.loader);
-      body.accept(library.loader.setLiteralTransformer);
+      body?.accept(library.loader.setLiteralTransformer);
     }
 
     // For async, async*, and sync* functions with declared return types, we
@@ -1158,6 +1163,14 @@
       constructor.initializers.add(initializer);
     }
     setParents(constructor.initializers, constructor);
+    if (transformSetLiterals) {
+      library.loader.setLiteralTransformer ??=
+          new SetLiteralTransformer(library.loader);
+      for (int i = 0; i < constructor.initializers.length; i++) {
+        constructor.initializers[i]
+            .accept(library.loader.setLiteralTransformer);
+      }
+    }
     if (constructor.function.body == null) {
       /// >If a generative constructor c is not a redirecting constructor
       /// >and no body is provided, then c implicitly has an empty body {}.
diff --git a/tests/language_2/set_literal_in_initializer.dart b/tests/language_2/set_literal_in_initializer.dart
new file mode 100644
index 0000000..04cc2d8
--- /dev/null
+++ b/tests/language_2/set_literal_in_initializer.dart
@@ -0,0 +1,16 @@
+// 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.
+
+class Bag {
+  final Set<Object> things;
+  Bag({Set<Object> things}) : this.things = things ?? <Object>{};
+  Bag.full({Set<Object> this.things = const {"cat"}});
+}
+
+main() {
+  new Bag();
+  new Bag(things: {});
+  new Bag.full();
+  new Bag.full(things: {});
+}