[analyzer] UI as code test cleanup

Change-Id: I73300a2aa5cfa1a9043454e462ac1df2840ee308
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97271
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
diff --git a/pkg/analyzer/test/generated/compile_time_error_code.dart b/pkg/analyzer/test/generated/compile_time_error_code.dart
index 4a4f04d..43b69e7 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code.dart
@@ -4228,48 +4228,6 @@
     ]);
   }
 
-  test_nonConstListElement() async {
-    Source source = addSource(r'''
-f(a) {
-  return const [a];
-}''');
-    await computeAnalysisResult(source);
-    assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
-    verify([source]);
-  }
-
-  test_nonConstListElementFromDeferredLibrary() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const [a.c];
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-
-  test_nonConstListElementFromDeferredLibrary_nested() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const [a.c + 1];
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-
   test_nonConstMapAsExpressionStatement_begin() async {
     Source source = addSource(r'''
 f() {
@@ -4328,90 +4286,6 @@
     verify([source]);
   }
 
-  test_nonConstMapKey() async {
-    Source source = addSource(r'''
-f(a) {
-  return const {a : 0};
-}''');
-    await computeAnalysisResult(source);
-    assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
-    verify([source]);
-  }
-
-  test_nonConstMapKeyFromDeferredLibrary() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const {a.c : 0};
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-
-  test_nonConstMapKeyFromDeferredLibrary_nested() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const {a.c + 1 : 0};
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-
-  test_nonConstMapValue() async {
-    Source source = addSource(r'''
-f(a) {
-  return const {'a' : a};
-}''');
-    await computeAnalysisResult(source);
-    assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]);
-    verify([source]);
-  }
-
-  test_nonConstMapValueFromDeferredLibrary() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const {'a' : a.c};
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-
-  test_nonConstMapValueFromDeferredLibrary_nested() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const {'a' : a.c + 1};
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-
   test_nonConstValueInInitializer_assert_condition() async {
     Source source = addSource(r'''
 class A {
diff --git a/pkg/analyzer/test/generated/compile_time_error_code_test.dart b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
index 2389261..1e3f433 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code_test.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
@@ -18,8 +18,6 @@
     defineReflectiveTests(ConstSetElementTypeImplementsEqualsTest);
     defineReflectiveTests(ControlFlowCollectionsTest);
     defineReflectiveTests(InvalidTypeArgumentInConstSetTest);
-    defineReflectiveTests(NonConstSetElementFromDeferredLibraryTest);
-    defineReflectiveTests(NonConstSetElementTest);
   });
 }
 
@@ -562,57 +560,3 @@
     verify([source]);
   }
 }
-
-@reflectiveTest
-class NonConstSetElementFromDeferredLibraryTest extends ResolverTestCase {
-  @override
-  bool get enableNewAnalysisDriver => true;
-
-  test_topLevelVariable_immediate() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const {a.c};
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-
-  test_topLevelVariable_nested() async {
-    await resolveWithErrors(<String>[
-      r'''
-library lib1;
-const int c = 1;''',
-      r'''
-library root;
-import 'lib1.dart' deferred as a;
-f() {
-  return const {a.c + 1};
-}'''
-    ], [
-      CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY
-    ]);
-  }
-}
-
-@reflectiveTest
-class NonConstSetElementTest extends ResolverTestCase {
-  @override
-  bool get enableNewAnalysisDriver => true;
-
-  test_parameter() async {
-    Source source = addSource(r'''
-f(a) {
-  return const {a};
-}''');
-    await computeAnalysisResult(source);
-    assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT]);
-    verify([source]);
-  }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart b/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart
index 5f92e7f..8c52012 100644
--- a/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/const_eval_throws_exception_test.dart
@@ -141,7 +141,7 @@
     ];
 
   test_ifElement_false_thenNotEvaluated() async {
-    assertNoErrorsInCode('''
+    await assertNoErrorsInCode('''
 const dynamic nil = null;
 const c = [if (1 < 0) nil + 1];
 ''');
@@ -169,7 +169,7 @@
   }
 
   test_ifElement_true_elseNotEvaluated() async {
-    assertNoErrorsInCode('''
+    await assertNoErrorsInCode('''
 const dynamic nil = null;
 const c = [if (0 < 1) 3 else nil + 1];
 ''');
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_list_element_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_from_deferred_library_test.dart
new file mode 100644
index 0000000..9a486ea
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_from_deferred_library_test.dart
@@ -0,0 +1,73 @@
+// 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.
+
+import 'package:analyzer/src/dart/analysis/experiments.dart';
+import 'package:analyzer/src/error/codes.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+  defineReflectiveSuite(() {
+    defineReflectiveTests(NonConstantListElementFromDeferredLibraryTest);
+    defineReflectiveTests(
+        NonConstantListValueFromDeferredLibraryWithUiAsCodeTest);
+  });
+}
+
+@reflectiveTest
+class NonConstantListElementFromDeferredLibraryTest
+    extends DriverResolutionTest {
+  test_const_topLevel_deferred() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const [a.c];
+''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_topLevel_deferred_nested() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const [a.c + 1];
+''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+}
+
+@reflectiveTest
+class NonConstantListValueFromDeferredLibraryWithUiAsCodeTest
+    extends NonConstantListElementFromDeferredLibraryTest {
+  @override
+  AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
+    ..enabledExperiments = [
+      EnableString.control_flow_collections,
+      EnableString.spread_collections
+    ];
+
+  @failingTest
+  test_const_ifElement_thenTrue_deferredElse() async {
+    // reports wrong error code (which is not crucial to fix)
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const [ if (cond) 'a' else a.c ];
+''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_ifElement_thenTrue_deferredThen() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const [ if (cond) a.c ];
+''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart
index f90a4c4..96fd900 100644
--- a/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_list_element_test.dart
@@ -25,6 +25,13 @@
 ''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
   }
 
+  test_const_topVar_nested() async {
+    await assertErrorsInCode(r'''
+final dynamic a = 0;
+var v = const [a + 1];
+''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
+  }
+
   test_nonConst_topVar() async {
     await assertNoErrorsInCode('''
 final dynamic a = 0;
@@ -43,6 +50,13 @@
       EnableString.spread_collections,
     ];
 
+  test_const_forElement() async {
+    await assertErrorsInCode(r'''
+const Set set = {};
+var v = const [for(final x in set) x];
+''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
+  }
+
   test_const_ifElement_thenElseFalse_finalElse() async {
     await assertErrorsInCode('''
 final dynamic a = 0;
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_key_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_from_deferred_library_test.dart
new file mode 100644
index 0000000..be77d50
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_from_deferred_library_test.dart
@@ -0,0 +1,71 @@
+// 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.
+
+import 'package:analyzer/src/dart/analysis/experiments.dart';
+import 'package:analyzer/src/error/codes.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+  defineReflectiveSuite(() {
+    defineReflectiveTests(NonConstantMapKeyFromDeferredLibraryTest);
+    defineReflectiveTests(NonConstantMapKeyFromDeferredLibraryWithUiAsCodeTest);
+  });
+}
+
+@reflectiveTest
+class NonConstantMapKeyFromDeferredLibraryTest extends DriverResolutionTest {
+  test_const_topLevel_deferred() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const {a.c : 0};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_topLevel_deferred_nested() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const {a.c + 1 : 0};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]);
+  }
+}
+
+@reflectiveTest
+class NonConstantMapKeyFromDeferredLibraryWithUiAsCodeTest
+    extends NonConstantMapKeyFromDeferredLibraryTest {
+  @override
+  AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
+    ..enabledExperiments = [
+      EnableString.control_flow_collections,
+      EnableString.spread_collections
+    ];
+
+  @failingTest
+  test_const_ifElement_thenTrue_deferredElse() async {
+// reports wrong error code
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const { if (cond) 0: 1 else a.c : 0};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_ifElement_thenTrue_deferredThen() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const { if (cond) a.c : 0};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY]);
+  }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_key_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_test.dart
new file mode 100644
index 0000000..95ec677
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_key_test.dart
@@ -0,0 +1,53 @@
+// 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.
+
+import 'package:analyzer/src/dart/analysis/experiments.dart';
+import 'package:analyzer/src/error/codes.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+  defineReflectiveSuite(() {
+    defineReflectiveTests(NonConstantMapKeyTest);
+    defineReflectiveTests(NonConstantMapKeyWithUiAsCodeTest);
+  });
+}
+
+@reflectiveTest
+class NonConstantMapKeyTest extends DriverResolutionTest {
+  test_const_topLevel() async {
+    await assertErrorsInCode(r'''
+final dynamic a = 0;
+var v = const {a : 0};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
+  }
+}
+
+@reflectiveTest
+class NonConstantMapKeyWithUiAsCodeTest extends NonConstantMapKeyTest {
+  @override
+  AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
+    ..enabledExperiments = [
+      EnableString.control_flow_collections,
+      EnableString.spread_collections
+    ];
+
+  test_const_ifElement_thenTrue_elseFinal() async {
+    await assertErrorsInCode(r'''
+final dynamic a = 0;
+const cond = true;
+var v = const {if (cond) 0: 1 else a : 0};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
+  }
+
+  test_const_ifElement_thenTrue_thenFinal() async {
+    await assertErrorsInCode(r'''
+final dynamic a = 0;
+const cond = true;
+var v = const {if (cond) a : 0};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
+  }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_value_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_from_deferred_library_test.dart
new file mode 100644
index 0000000..ce04f02
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_from_deferred_library_test.dart
@@ -0,0 +1,72 @@
+// 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.
+
+import 'package:analyzer/src/dart/analysis/experiments.dart';
+import 'package:analyzer/src/error/codes.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+  defineReflectiveSuite(() {
+    defineReflectiveTests(NonConstantMapValueFromDeferredLibraryTest);
+    defineReflectiveTests(
+        NonConstantMapValueFromDeferredLibraryWithUiAsCodeTest);
+  });
+}
+
+@reflectiveTest
+class NonConstantMapValueFromDeferredLibraryTest extends DriverResolutionTest {
+  test_const_topLevel_deferred() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const {'a' : a.c};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_topLevel_deferred_nested() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const {'a' : a.c + 1};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]);
+  }
+}
+
+@reflectiveTest
+class NonConstantMapValueFromDeferredLibraryWithUiAsCodeTest
+    extends NonConstantMapValueFromDeferredLibraryTest {
+  @override
+  AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
+    ..enabledExperiments = [
+      EnableString.control_flow_collections,
+      EnableString.spread_collections
+    ];
+
+  @failingTest
+  test_const_ifElement_thenTrue_elseDeferred() async {
+    // reports wrong error code
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const { if (cond) 'a': 'b' else 'c' : a.c};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_ifElement_thenTrue_thenDeferred() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const { if (cond) 'a' : a.c};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY]);
+  }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_map_value_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_test.dart
new file mode 100644
index 0000000..75b20d5
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_map_value_test.dart
@@ -0,0 +1,53 @@
+// 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.
+
+import 'package:analyzer/src/dart/analysis/experiments.dart';
+import 'package:analyzer/src/error/codes.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+  defineReflectiveSuite(() {
+    defineReflectiveTests(NonConstantMapValueTest);
+    defineReflectiveTests(NonConstantMapValueWithUiAsCodeTest);
+  });
+}
+
+@reflectiveTest
+class NonConstantMapValueTest extends DriverResolutionTest {
+  test_const_topLevel() async {
+    await assertErrorsInCode(r'''
+final dynamic a = 0;
+var v = const {'a' : a};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]);
+  }
+}
+
+@reflectiveTest
+class NonConstantMapValueWithUiAsCodeTest extends NonConstantMapValueTest {
+  @override
+  AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
+    ..enabledExperiments = [
+      EnableString.control_flow_collections,
+      EnableString.spread_collections
+    ];
+
+  test_const_ifTrue_elseFinal() async {
+    await assertErrorsInCode(r'''
+final dynamic a = 0;
+const cond = true;
+var v = const {if (cond) 'a': 'b', 'c' : a};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]);
+  }
+
+  test_const_ifTrue_thenFinal() async {
+    await assertErrorsInCode(r'''
+final dynamic a = 0;
+const cond = true;
+var v = const {if (cond) 'a' : a};
+''', [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]);
+  }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_set_element_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_set_element_from_deferred_library_test.dart
new file mode 100644
index 0000000..59bdddb
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_set_element_from_deferred_library_test.dart
@@ -0,0 +1,73 @@
+// 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.
+
+import 'package:analyzer/src/dart/analysis/experiments.dart';
+import 'package:analyzer/src/error/codes.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/driver_resolution.dart';
+
+main() {
+  defineReflectiveSuite(() {
+    defineReflectiveTests(NonConstantSetElementFromDeferredLibraryTest);
+    defineReflectiveTests(
+        NonConstantSetElementFromDeferredLibraryWithUiAsCodeTest);
+  });
+}
+
+@reflectiveTest
+class NonConstantSetElementFromDeferredLibraryTest
+    extends DriverResolutionTest {
+  test_const_topLevel_deferred() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const {a.c};
+''', [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_topLevel_deferred_nested() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+var v = const {a.c + 1};
+''', [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+}
+
+@reflectiveTest
+class NonConstantSetElementFromDeferredLibraryWithUiAsCodeTest
+    extends NonConstantSetElementFromDeferredLibraryTest {
+  @override
+  AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
+    ..enabledExperiments = [
+      EnableString.control_flow_collections,
+      EnableString.spread_collections
+    ];
+
+  @failingTest
+  test_const_ifElement_thenTrue_elseDeferred() async {
+    // reports wrong error code
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const {if (cond) null else a.c};
+''', [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+
+  test_const_ifElement_thenTrue_thenDeferred() async {
+    newFile(convertPath('/test/lib/lib1.dart'), content: r'''
+const int c = 1;''');
+    await assertErrorsInCode(r'''
+import 'lib1.dart' deferred as a;
+const cond = true;
+var v = const {if (cond) a.c};
+''', [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT_FROM_DEFERRED_LIBRARY]);
+  }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart
index 1d8c475..ac0fdf9 100644
--- a/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/non_constant_set_element_test.dart
@@ -18,6 +18,13 @@
 
 @reflectiveTest
 class NonConstantSetElementTest extends DriverResolutionTest {
+  test_const_parameter() async {
+    await assertErrorsInCode(r'''
+f(a) {
+  return const {a};
+}''', [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT]);
+  }
+
   test_const_topVar() async {
     await assertErrorsInCode('''
 final dynamic a = 0;
@@ -97,4 +104,11 @@
 var v = const <int>{if (1 > 0) a};
 ''', [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT]);
   }
+
+  test_const_spread_final() async {
+    await assertErrorsInCode(r'''
+final Set x = null;
+var v = const {...x};
+''', [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT]);
+  }
 }
diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart
index 1383247..a942058 100644
--- a/pkg/analyzer/test/src/diagnostics/test_all.dart
+++ b/pkg/analyzer/test/src/diagnostics/test_all.dart
@@ -48,8 +48,18 @@
 import 'must_be_immutable_test.dart' as must_be_immutable;
 import 'must_call_super_test.dart' as must_call_super;
 import 'non_bool_condition_test.dart' as non_bool_condition;
+import 'non_constant_list_element_from_deferred_library_test.dart'
+    as non_constant_list_element_from_deferred_library;
 import 'non_constant_list_element_test.dart' as non_constant_list_element;
 import 'non_constant_map_element_test.dart' as non_constant_map_element;
+import 'non_constant_map_key_from_deferred_library_test.dart'
+    as non_constant_map_key_from_deferred_library;
+import 'non_constant_map_key_test.dart' as non_constant_map_key;
+import 'non_constant_map_value_from_deferred_library_test.dart'
+    as non_constant_map_value_from_deferred_library;
+import 'non_constant_map_value_test.dart' as non_constant_map_value;
+import 'non_constant_set_element_from_deferred_library_test.dart'
+    as non_constant_set_element_from_deferred_library;
 import 'non_constant_set_element_test.dart' as non_constant_set_element;
 import 'not_iterable_spread_test.dart' as not_iterable_spread;
 import 'not_map_spread_test.dart' as not_map_spread;
@@ -126,6 +136,12 @@
     non_constant_set_element.main();
     not_iterable_spread.main();
     not_map_spread.main();
+    non_constant_list_element_from_deferred_library.main();
+    non_constant_map_key_from_deferred_library.main();
+    non_constant_map_key.main();
+    non_constant_map_value_from_deferred_library.main();
+    non_constant_map_value.main();
+    non_constant_set_element_from_deferred_library.main();
     set_element_type_not_assignable.main();
     subtype_of_sealed_class.main();
     top_level_instance_getter.main();