Stop compilation early on CFE compile-time errors

Change-Id: Ie93af5880bbd0b9f0c72aa6c1832550bf9025595
Reviewed-on: https://dart-review.googlesource.com/75160
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart
index be24ef3..0ad98b3 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -267,6 +267,9 @@
     // Note: libraries may be null because of errors trying to find files or
     // parse-time errors (when using `package:front_end` as a loader).
     if (loadedLibraries == null) return;
+    if (compilationFailed && !options.generateCodeWithCompileTimeErrors) {
+      return;
+    }
     _mainLibraryUri = loadedLibraries.rootLibraryUri;
     processLoadedLibraries(loadedLibraries);
     compileLoadedLibraries(loadedLibraries);
diff --git a/pkg/compiler/lib/src/kernel/element_map_impl.dart b/pkg/compiler/lib/src/kernel/element_map_impl.dart
index 4e66347..c50d35b 100644
--- a/pkg/compiler/lib/src/kernel/element_map_impl.dart
+++ b/pkg/compiler/lib/src/kernel/element_map_impl.dart
@@ -74,7 +74,6 @@
   KernelConstantEnvironment _constantEnvironment;
   KernelDartTypes _types;
   ir.TypeEnvironment _typeEnvironment;
-  bool _isStaticTypePrepared = false;
 
   /// Library environment. Used for fast lookup.
   ProgramEnv env = new ProgramEnv();
@@ -711,18 +710,10 @@
   }
 
   DartType getStaticType(ir.Expression node) {
-    if (!_isStaticTypePrepared) {
-      _isStaticTypePrepared = true;
-      try {
-        _typeEnvironment ??= new ir.TypeEnvironment(
-            new ir.CoreTypes(env.mainComponent),
-            new ir.ClassHierarchy(env.mainComponent));
-      } catch (e) {}
-    }
     if (_typeEnvironment == null) {
-      // The class hierarchy crashes on multiple inheritance. Use `dynamic`
-      // as static type.
-      return commonElements.dynamicType;
+      _typeEnvironment ??= new ir.TypeEnvironment(
+          new ir.CoreTypes(env.mainComponent),
+          new ir.ClassHierarchy(env.mainComponent));
     }
     ir.TreeNode enclosingClass = node;
     while (enclosingClass != null && enclosingClass is! ir.Class) {
diff --git a/tests/co19_2/co19_2-dart2js.status b/tests/co19_2/co19_2-dart2js.status
index b184b75..523236a 100644
--- a/tests/co19_2/co19_2-dart2js.status
+++ b/tests/co19_2/co19_2-dart2js.status
@@ -2209,10 +2209,6 @@
 WebPlatformTest/webstorage/storage_session_setitem_quotaexceedederr_t01: RuntimeError
 
 [ $compiler == dart2js && $runtime != chrome && $runtime != ff && $runtime != safari && !$fast_startup ]
-Language/Functions/setter_modifier_t02: Crash
-Language/Functions/setter_modifier_t03: Crash
-Language/Functions/setter_modifier_t05: Crash
-Language/Functions/setter_modifier_t06: Crash
 LayoutTests/fast/animation/request-animation-frame-callback-id_t01: RuntimeError
 LayoutTests/fast/animation/request-animation-frame-cancel_t01: RuntimeError
 LayoutTests/fast/animation/request-animation-frame-timestamps-advance_t01: RuntimeError
@@ -3490,8 +3486,6 @@
 Language/Expressions/Shift/integer_t02: CompileTimeError
 Language/Expressions/Type_Cast/syntax_t01: RuntimeError
 Language/Expressions/Unary_Expressions/variable_negative_t03: RuntimeError
-Language/Functions/setter_modifier_t01: Crash
-Language/Functions/setter_modifier_t04: Crash
 Language/Libraries_and_Scripts/Scripts/top_level_main_t01: CompileTimeError
 Language/Libraries_and_Scripts/top_level_syntax_t01: CompileTimeError
 Language/Metadata/before_ctor_t02: RuntimeError
diff --git a/tests/compiler/dart2js/model/subtype_test.dart b/tests/compiler/dart2js/model/subtype_test.dart
index 8cd0fb4..9a43a69 100644
--- a/tests/compiler/dart2js/model/subtype_test.dart
+++ b/tests/compiler/dart2js/model/subtype_test.dart
@@ -59,7 +59,7 @@
       main() {
         new C();
       }
-      """).then((env) {
+      """, expectNoErrors: true).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S,
         {bool expectMoreSpecific}) {
       testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@@ -318,7 +318,7 @@
         a.m4(null, null);
         a.m5(null, null);
       }
-      """).then((env) {
+      """, expectNoErrors: true).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S,
         {bool expectMoreSpecific}) {
       testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@@ -371,7 +371,8 @@
   main() {
     ${createUses(functionTypesData)}
   }
-  """))
+  """),
+          expectNoErrors: true)
       .then(functionSubtypingHelper);
 }
 
@@ -381,7 +382,8 @@
   main() {
     ${createUses(functionTypesData)}
   }
-  """))
+  """),
+          expectNoErrors: true)
       .then(functionSubtypingHelper);
 }
 
@@ -463,7 +465,8 @@
   main() {
     ${createUses(optionalFunctionTypesData)}
   }
-  """))
+  """),
+          expectNoErrors: true)
       .then((env) => functionSubtypingOptionalHelper(env));
 }
 
@@ -473,7 +476,8 @@
   main() {
     ${createUses(optionalFunctionTypesData)}
   }
-  """))
+  """),
+          expectNoErrors: true)
       .then((env) => functionSubtypingOptionalHelper(env));
 }
 
@@ -543,7 +547,8 @@
   main() {
     ${createUses(namedFunctionTypesData)}
   }
-  """))
+  """),
+          expectNoErrors: true)
       .then((env) => functionSubtypingNamedHelper(env));
 }
 
@@ -553,7 +558,8 @@
   main() {
     ${createUses(namedFunctionTypesData)}
   }
-  """))
+  """),
+          expectNoErrors: true)
       .then((env) => functionSubtypingNamedHelper(env));
 }
 
@@ -601,10 +607,6 @@
       class D<T extends int> {}
       class E<T extends S, S extends num> {}
       class F<T extends num, S extends T> {}
-      class G<T extends T> {}
-      class H<T extends S, S extends T> {}
-      class I<T extends S, S extends U, U extends T> {}
-      class J<T extends S, S extends U, U extends S> {}
 
       main() {
         new A();
@@ -613,12 +615,8 @@
         new D();
         new E<num, int>();
         new F();
-        new G();
-        new H();
-        new I();
-        new J();
       }
-      """).then((env) {
+      """, expectNoErrors: true).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S,
         {bool expectMoreSpecific}) {
       testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@@ -642,19 +640,6 @@
     ClassEntity F = env.getClass('F');
     TypeVariableType F_T = getTypeVariable(F, 0);
     TypeVariableType F_S = getTypeVariable(F, 1);
-    ClassEntity G = env.getClass('G');
-    TypeVariableType G_T = getTypeVariable(G, 0);
-    ClassEntity H = env.getClass('H');
-    TypeVariableType H_T = getTypeVariable(H, 0);
-    TypeVariableType H_S = getTypeVariable(H, 1);
-    ClassEntity I = env.getClass('I');
-    TypeVariableType I_T = getTypeVariable(I, 0);
-    TypeVariableType I_S = getTypeVariable(I, 1);
-    TypeVariableType I_U = getTypeVariable(I, 2);
-    ClassEntity J = env.getClass('J');
-    TypeVariableType J_T = getTypeVariable(J, 0);
-    TypeVariableType J_S = getTypeVariable(J, 1);
-    TypeVariableType J_U = getTypeVariable(J, 2);
 
     DartType Object_ = env['Object'];
     DartType num_ = env['num'];
@@ -735,96 +720,6 @@
     expect(true, F_S, F_S);
     expect(true, F_S, F_T);
     expect(false, F_S, A_T);
-
-    // class G<T extends T> {}
-    expect(true, G_T, Object_);
-    expect(false, G_T, num_);
-    expect(false, G_T, int_);
-    expect(false, G_T, String_);
-    expect(true, G_T, dynamic_);
-    expect(true, G_T, G_T);
-    expect(false, G_T, A_T);
-
-    // class H<T extends S, S extends T> {}
-    expect(true, H_T, Object_);
-    expect(false, H_T, num_);
-    expect(false, H_T, int_);
-    expect(false, H_T, String_);
-    expect(true, H_T, dynamic_);
-    expect(true, H_T, H_T);
-    expect(true, H_T, H_S);
-    expect(false, H_T, A_T);
-
-    expect(true, H_S, Object_);
-    expect(false, H_S, num_);
-    expect(false, H_S, int_);
-    expect(false, H_S, String_);
-    expect(true, H_S, dynamic_);
-    expect(true, H_S, H_T);
-    expect(true, H_S, H_S);
-    expect(false, H_S, A_T);
-
-    // class I<T extends S, S extends U, U extends T> {}
-    expect(true, I_T, Object_);
-    expect(false, I_T, num_);
-    expect(false, I_T, int_);
-    expect(false, I_T, String_);
-    expect(true, I_T, dynamic_);
-    expect(true, I_T, I_T);
-    expect(true, I_T, I_S);
-    expect(true, I_T, I_U);
-    expect(false, I_T, A_T);
-
-    expect(true, I_S, Object_);
-    expect(false, I_S, num_);
-    expect(false, I_S, int_);
-    expect(false, I_S, String_);
-    expect(true, I_S, dynamic_);
-    expect(true, I_S, I_T);
-    expect(true, I_S, I_S);
-    expect(true, I_S, I_U);
-    expect(false, I_S, A_T);
-
-    expect(true, I_U, Object_);
-    expect(false, I_U, num_);
-    expect(false, I_U, int_);
-    expect(false, I_U, String_);
-    expect(true, I_U, dynamic_);
-    expect(true, I_U, I_T);
-    expect(true, I_U, I_S);
-    expect(true, I_U, I_U);
-    expect(false, I_U, A_T);
-
-    // class J<T extends S, S extends U, U extends S> {}
-    expect(true, J_T, Object_);
-    expect(false, J_T, num_);
-    expect(false, J_T, int_);
-    expect(false, J_T, String_);
-    expect(true, J_T, dynamic_);
-    expect(true, J_T, J_T);
-    expect(true, J_T, J_S);
-    expect(true, J_T, J_U);
-    expect(false, J_T, A_T);
-
-    expect(true, J_S, Object_);
-    expect(false, J_S, num_);
-    expect(false, J_S, int_);
-    expect(false, J_S, String_);
-    expect(true, J_S, dynamic_);
-    expect(false, J_S, J_T);
-    expect(true, J_S, J_S);
-    expect(true, J_S, J_U);
-    expect(false, J_S, A_T);
-
-    expect(true, J_U, Object_);
-    expect(false, J_U, num_);
-    expect(false, J_U, int_);
-    expect(false, J_U, String_);
-    expect(true, J_U, dynamic_);
-    expect(false, J_U, J_T);
-    expect(true, J_U, J_S);
-    expect(true, J_U, J_U);
-    expect(false, J_U, A_T);
   });
 }
 
@@ -855,7 +750,7 @@
         takeVoid(null);
         takeObject(null);
       }
-      """).then((env) {
+      """, expectNoErrors: true).then((env) {
     void expect(bool expectSubtype, DartType T, DartType S) {
       Expect.equals(expectSubtype, env.isSubtype(T, S), '$T <: $S');
       if (expectSubtype) {
diff --git a/tests/language_2/language_2_dart2js.status b/tests/language_2/language_2_dart2js.status
index 25b6963..241f8f57 100644
--- a/tests/language_2/language_2_dart2js.status
+++ b/tests/language_2/language_2_dart2js.status
@@ -463,8 +463,6 @@
 redirecting_factory_malbounded_test/01: MissingCompileTimeError
 regress_13462_1_test: RuntimeError
 regress_18535_test: RuntimeError
-sync_generator2_test/41: Crash # 'file:*/pkg/compiler/lib/src/kernel/element_map_impl.dart': Failed assertion: line 939 pos 18: 'asyncMarker == AsyncMarker.SYNC': is not true.
-sync_generator2_test/52: Crash # 'file:*/pkg/compiler/lib/src/kernel/element_map_impl.dart': Failed assertion: line 939 pos 18: 'asyncMarker == AsyncMarker.SYNC': is not true.
 type_literal_prefix_call_test/00: MissingCompileTimeError
 type_promotion_logical_and_test/01: MissingCompileTimeError
 type_variable_bounds_test/02: Crash # NoSuchMethodError: The method 'accept' was called on null.