Convert Unspecified to NonConst[Constructor|Factory]

Change-Id: If71220e1ee7b8a57daea228191c9fafef22b6bc2
Reviewed-on: https://dart-review.googlesource.com/64920
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
diff --git a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
index 18b2133..20b498a 100644
--- a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
+++ b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
@@ -4899,6 +4899,31 @@
 }
 
 // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
+const Code<Null> codeNonConstConstructor = messageNonConstConstructor;
+
+// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
+const MessageCode messageNonConstConstructor = const MessageCode(
+    "NonConstConstructor",
+    analyzerCode: "NOT_CONSTANT_EXPRESSION",
+    dart2jsCode: "*fatal*",
+    severity: Severity.error,
+    message:
+        r"""Cannot invoke a non-'const' constructor where a const expression is expected.""",
+    tip: r"""Try using a constructor or factory that is 'const'.""");
+
+// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
+const Code<Null> codeNonConstFactory = messageNonConstFactory;
+
+// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
+const MessageCode messageNonConstFactory = const MessageCode("NonConstFactory",
+    analyzerCode: "NOT_CONSTANT_EXPRESSION",
+    dart2jsCode: "*fatal*",
+    severity: Severity.error,
+    message:
+        r"""Cannot invoke a non-'const' factory where a const expression is expected.""",
+    tip: r"""Try using a constructor or factory that is 'const'.""");
+
+// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
 const Code<Null> codeNonInstanceTypeVariableUse =
     messageNonInstanceTypeVariableUse;
 
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 cf2eeb0..9282ec7 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -2785,7 +2785,7 @@
       if ((isConst || constantContext == ConstantContext.inferred) &&
           !target.isConst) {
         return deprecated_buildCompileTimeError(
-            "Not a const constructor.", charOffset);
+            null, charOffset, fasta.messageNonConstConstructor);
       }
       return new ConstructorInvocationJudgment(
           target, forest.castArguments(arguments),
@@ -2799,7 +2799,7 @@
         if ((isConst || constantContext == ConstantContext.inferred) &&
             !procedure.isConst) {
           return deprecated_buildCompileTimeError(
-              "Not a const factory.", charOffset);
+              null, charOffset, fasta.messageNonConstFactory);
         }
         return new FactoryConstructorInvocationJudgment(
             target, forest.castArguments(arguments),
diff --git a/pkg/front_end/messages.status b/pkg/front_end/messages.status
index 4ef4bdc..8c8273c 100644
--- a/pkg/front_end/messages.status
+++ b/pkg/front_end/messages.status
@@ -245,6 +245,8 @@
 NoUnnamedConstructorInObject/analyzerCode: Fail
 NoUnnamedConstructorInObject/example: Fail
 NonAsciiIdentifier/expression: Fail
+NonConstConstructor/example: Fail
+NonConstFactory/example: Fail
 NonInstanceTypeVariableUse/example: Fail
 NonPartOfDirectiveInPart/script1: Fail
 NotAConstantExpression/example: Fail
diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml
index d27a9c3..99b369c 100644
--- a/pkg/front_end/messages.yaml
+++ b/pkg/front_end/messages.yaml
@@ -474,6 +474,20 @@
   script:
     - "class C { const factory C() {} }"
 
+NonConstFactory:
+  template: "Cannot invoke a non-'const' factory where a const expression is expected."
+  tip: "Try using a constructor or factory that is 'const'."
+  severity: ERROR
+  analyzerCode: NOT_CONSTANT_EXPRESSION
+  dart2jsCode: "*fatal*"
+
+NonConstConstructor:
+  template: "Cannot invoke a non-'const' constructor where a const expression is expected."
+  tip: "Try using a constructor or factory that is 'const'."
+  severity: ERROR
+  analyzerCode: NOT_CONSTANT_EXPRESSION
+  dart2jsCode: "*fatal*"
+
 ConstAfterFactory:
   template: "The modifier 'const' should be before the modifier 'factory'."
   tip: "Try re-ordering the modifiers."
diff --git a/pkg/front_end/testcases/magic_const.dart.direct.expect b/pkg/front_end/testcases/magic_const.dart.direct.expect
index 31bfe5f..0e35d4e 100644
--- a/pkg/front_end/testcases/magic_const.dart.direct.expect
+++ b/pkg/front_end/testcases/magic_const.dart.direct.expect
@@ -14,7 +14,8 @@
 }
 static method foo({dynamic a = new self::Constant::•(), dynamic b = new self::Constant::•(), dynamic c = <dynamic>[]}) → dynamic {}
 static method test() → dynamic {
-  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Not a const constructor.
+  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Cannot invoke a non-'const' constructor where a const expression is expected.
+Try using a constructor or factory that is 'const'.
   const NotConstant();
         ^";
   new self::Constant::•();
diff --git a/pkg/front_end/testcases/magic_const.dart.direct.transformed.expect b/pkg/front_end/testcases/magic_const.dart.direct.transformed.expect
index 31bfe5f..0e35d4e 100644
--- a/pkg/front_end/testcases/magic_const.dart.direct.transformed.expect
+++ b/pkg/front_end/testcases/magic_const.dart.direct.transformed.expect
@@ -14,7 +14,8 @@
 }
 static method foo({dynamic a = new self::Constant::•(), dynamic b = new self::Constant::•(), dynamic c = <dynamic>[]}) → dynamic {}
 static method test() → dynamic {
-  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Not a const constructor.
+  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Cannot invoke a non-'const' constructor where a const expression is expected.
+Try using a constructor or factory that is 'const'.
   const NotConstant();
         ^";
   new self::Constant::•();
diff --git a/pkg/front_end/testcases/magic_const.dart.strong.expect b/pkg/front_end/testcases/magic_const.dart.strong.expect
index d60f57e..990b71e 100644
--- a/pkg/front_end/testcases/magic_const.dart.strong.expect
+++ b/pkg/front_end/testcases/magic_const.dart.strong.expect
@@ -14,7 +14,8 @@
 }
 static method foo({dynamic a = new self::Constant::•(), dynamic b = new self::Constant::•(), dynamic c = <dynamic>[]}) → dynamic {}
 static method test() → dynamic {
-  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Not a const constructor.
+  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Cannot invoke a non-'const' constructor where a const expression is expected.
+Try using a constructor or factory that is 'const'.
   const NotConstant();
         ^";
   new self::Constant::•();
diff --git a/pkg/front_end/testcases/magic_const.dart.strong.transformed.expect b/pkg/front_end/testcases/magic_const.dart.strong.transformed.expect
index d60f57e..990b71e 100644
--- a/pkg/front_end/testcases/magic_const.dart.strong.transformed.expect
+++ b/pkg/front_end/testcases/magic_const.dart.strong.transformed.expect
@@ -14,7 +14,8 @@
 }
 static method foo({dynamic a = new self::Constant::•(), dynamic b = new self::Constant::•(), dynamic c = <dynamic>[]}) → dynamic {}
 static method test() → dynamic {
-  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Not a const constructor.
+  invalid-expression "pkg/front_end/testcases/magic_const.dart:18:9: Error: Cannot invoke a non-'const' constructor where a const expression is expected.
+Try using a constructor or factory that is 'const'.
   const NotConstant();
         ^";
   new self::Constant::•();