[dart2js] Simplify message templates

Change-Id: I8e3f33664a3e7944e1b2d6bcf09bebd74c7b826e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214003
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Stephen Adams 2021-09-21 12:45:02 +00:00 committed by commit-bot@chromium.org
parent b3cfd293ad
commit 5c719b3bd3
2 changed files with 114 additions and 628 deletions

View file

@ -1,217 +0,0 @@
// Copyright (c) 2015, 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.
/*
DON'T EDIT. GENERATED. DON'T EDIT.
This file has been generated by 'publish.dart' in the dart_messages package.
Messages are maintained in `lib/shared_messages.dart` of that same package.
After any change to that file, run `bin/publish.dart` to generate a new version
of the json, dart2js and analyzer representations.
*/
import '../messages.dart' show MessageKind, MessageTemplate;
const Map<MessageKind, MessageTemplate> TEMPLATES =
const <MessageKind, MessageTemplate>{
MessageKind.CONST_CONSTRUCTOR_WITH_BODY: const MessageTemplate(
MessageKind.CONST_CONSTRUCTOR_WITH_BODY,
"Const constructor can't have a body.",
howToFix: "Try removing the 'const' keyword or the body.",
examples: const [
r"""
class C {
const C() {}
}
main() => new C();""",
]), // Generated. Don't edit.
MessageKind.CONST_FACTORY: const MessageTemplate(MessageKind.CONST_FACTORY,
"Only redirecting factory constructors can be declared to be 'const'.",
howToFix:
"Try removing the 'const' keyword or replacing the body with '=' followed by a valid target.",
examples: const [
r"""
class C {
const factory C() {}
}
main() => new C();""",
]), // Generated. Don't edit.
MessageKind.EXTRANEOUS_MODIFIER: const MessageTemplate(
MessageKind.EXTRANEOUS_MODIFIER,
"Can't have modifier '#{modifier}' here.",
howToFix: "Try removing '#{modifier}'.",
examples: const [
"var String foo; main(){}",
"var final foo; main(){}",
"var var foo; main(){}",
"var const foo; main(){}",
"var abstract foo; main(){}",
"var static foo; main(){}",
"var external foo; main(){}",
"final var foo; main(){}",
"var var foo; main(){}",
"const var foo; main(){}",
"abstract var foo; main(){}",
"static var foo; main(){}",
"external var foo; main(){}",
]), // Generated. Don't edit.
MessageKind.EXTRANEOUS_MODIFIER_REPLACE: const MessageTemplate(
MessageKind.EXTRANEOUS_MODIFIER_REPLACE,
"Can't have modifier '#{modifier}' here.",
howToFix:
"Try replacing modifier '#{modifier}' with 'var', 'final', or a type.",
examples: const [
"set foo; main(){}",
"abstract foo; main(){}",
"static foo; main(){}",
"external foo; main(){}",
]), // Generated. Don't edit.
MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE: const MessageTemplate(
MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE,
"Constructors can't have a return type.",
howToFix: "Try removing the return type.",
examples: const [
"class A { int A() {} } main() { new A(); }",
]), // Generated. Don't edit.
MessageKind.MISSING_EXPRESSION_IN_THROW: const MessageTemplate(
MessageKind.MISSING_EXPRESSION_IN_THROW,
"Missing expression after 'throw'.",
howToFix: "Did you mean 'rethrow'?"), // Generated. Don't edit.
MessageKind.RETHROW_OUTSIDE_CATCH: const MessageTemplate(
MessageKind.RETHROW_OUTSIDE_CATCH,
"Rethrow must be inside of catch clause.",
howToFix:
"Try moving the expression into a catch clause, or using a 'throw' expression.",
examples: const [
"main() { rethrow; }",
]), // Generated. Don't edit.
MessageKind.RETURN_IN_GENERATIVE_CONSTRUCTOR: const MessageTemplate(
MessageKind.RETURN_IN_GENERATIVE_CONSTRUCTOR,
"Constructors can't return values.",
howToFix:
"Try removing the return statement or using a factory constructor.",
examples: const [
r"""
class C {
C() {
return 1;
}
}
main() => new C();""",
]), // Generated. Don't edit.
MessageKind.RETURN_IN_GENERATOR: const MessageTemplate(
MessageKind.RETURN_IN_GENERATOR,
"Can't return a value from a generator function (using the '#{modifier}' modifier).",
howToFix:
"Try removing the value, replacing 'return' with 'yield' or changing the method body modifier.",
examples: const [
r"""
foo() async* { return 0; }
main() => foo();
""",
r"""
foo() sync* { return 0; }
main() => foo();
""",
]), // Generated. Don't edit.
MessageKind.NOT_ASSIGNABLE: const MessageTemplate(MessageKind.NOT_ASSIGNABLE,
"'#{fromType}' is not assignable to '#{toType}'."), // Generated. Don't edit.
MessageKind.FORIN_NOT_ASSIGNABLE: const MessageTemplate(
MessageKind.FORIN_NOT_ASSIGNABLE,
"The element type '#{currentType}' of '#{expressionType}' is not assignable to '#{elementType}'.",
examples: const [
r"""
main() {
List<int> list = <int>[1, 2];
for (String x in list) x;
}
""",
]), // Generated. Don't edit.
MessageKind.CANNOT_RESOLVE: const MessageTemplate(MessageKind.CANNOT_RESOLVE,
"Can't resolve '#{name}'."), // Generated. Don't edit.
MessageKind.UNDEFINED_METHOD: const MessageTemplate(
MessageKind.UNDEFINED_METHOD,
"The method '#{memberName}' is not defined for the class '#{className}'.",
examples: const [
r"""
class A {
foo() { bar(); }
}
main() { new A().foo(); }
""",
]), // Generated. Don't edit.
MessageKind.UNDEFINED_GETTER: const MessageTemplate(
MessageKind.UNDEFINED_GETTER,
"The getter '#{memberName}' is not defined for the class '#{className}'.",
examples: const [
"class A {} main() { new A().x; }",
"class A {} main() { A.x; }",
]), // Generated. Don't edit.
MessageKind.UNDEFINED_INSTANCE_GETTER_BUT_SETTER: const MessageTemplate(
MessageKind.UNDEFINED_INSTANCE_GETTER_BUT_SETTER,
"The setter '#{memberName}' in class '#{className}' can not be used as a getter.",
examples: const [
"class A { set x(y) {} } main() { new A().x; }",
]), // Generated. Don't edit.
MessageKind.UNDEFINED_OPERATOR: const MessageTemplate(
MessageKind.UNDEFINED_OPERATOR,
"The operator '#{memberName}' is not defined for the class '#{className}'.",
examples: const [
"class A {} main() { new A() + 3; }",
]), // Generated. Don't edit.
MessageKind.UNDEFINED_SETTER: const MessageTemplate(
MessageKind.UNDEFINED_SETTER,
"The setter '#{memberName}' is not defined for the class '#{className}'.",
examples: const [
"class A {} main() { new A().x = 499; }",
]), // Generated. Don't edit.
MessageKind.NO_SUCH_SUPER_MEMBER: const MessageTemplate(
MessageKind.NO_SUCH_SUPER_MEMBER,
"Can't resolve '#{memberName}' in a superclass of '#{className}'."), // Generated. Don't edit.
MessageKind.UNDEFINED_SUPER_SETTER: const MessageTemplate(
MessageKind.UNDEFINED_SUPER_SETTER,
"The setter '#{memberName}' is not defined in a superclass of '#{className}'.",
examples: const [
r"""
class A {}
class B extends A {
foo() { super.x = 499; }
}
main() { new B().foo(); }
""",
]), // Generated. Don't edit.
MessageKind.UNDEFINED_STATIC_GETTER_BUT_SETTER: const MessageTemplate(
MessageKind.UNDEFINED_STATIC_GETTER_BUT_SETTER,
"Cannot resolve getter '#{name}'.",
examples: const [
"set foo(x) {} main() { foo; }",
]), // Generated. Don't edit.
MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER: const MessageTemplate(
MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER,
"Cannot resolve setter '#{name}'.",
examples: const [
r"""
main() {
final x = 1;
x = 2;
}""",
r"""
main() {
const x = 1;
x = 2;
}
""",
r"""
final x = 1;
main() { x = 3; }
""",
r"""
const x = 1;
main() { x = 3; }
""",
"get foo => null main() { foo = 5; }",
"const foo = 0 main() { foo = 5; }",
]), // Generated. Don't edit.
};

View file

@ -14,7 +14,6 @@
/// location of the existing element.
library dart2js.messages;
import 'generated/shared_messages.dart' as shared_messages;
import '../commandline_options.dart';
import '../options.dart';
import 'invariant.dart' show failedAt;
@ -25,81 +24,23 @@ const DONT_KNOW_HOW_TO_FIX = "Computer says no!";
/// Keys for the [MessageTemplate]s.
enum MessageKind {
ABSTRACT_GETTER,
CANNOT_RESOLVE,
COMPILER_CRASHED,
COMPLEX_RETURNING_NSM,
COMPLEX_THROWING_NSM,
CONST_CONSTRUCTOR_WITH_BODY,
CONST_FACTORY,
CONSTRUCTOR_WITH_RETURN_TYPE,
CYCLIC_COMPILE_TIME_CONSTANTS,
DIRECTLY_THROWING_NSM,
EQUAL_MAP_ENTRY_KEY,
EQUAL_SET_ENTRY,
EXTRANEOUS_MODIFIER,
EXTRANEOUS_MODIFIER_REPLACE,
FORIN_NOT_ASSIGNABLE,
GENERIC,
HIDDEN_HINTS,
HIDDEN_WARNINGS,
HIDDEN_WARNINGS_HINTS,
IMPLICIT_JS_INTEROP_FIELD_NOT_SUPPORTED,
INVALID_ASSERT_VALUE,
INVALID_ASSERT_VALUE_MESSAGE,
INVALID_BOOL_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE,
INVALID_CONSTANT_CAST,
INVALID_CONSTANT_ADD_TYPES,
INVALID_CONSTANT_BINARY_INT_TYPE,
INVALID_CONSTANT_BINARY_NUM_TYPE,
INVALID_CONSTANT_BINARY_PRIMITIVE_TYPE,
INVALID_CONSTANT_COMPLEMENT_TYPE,
INVALID_CONSTANT_CONDITIONAL_TYPE,
INVALID_CONSTANT_CONSTRUCTOR,
INVALID_CONSTANT_DIV,
INVALID_CONSTANT_INDEX,
INVALID_CONSTANT_INTERPOLATION_TYPE,
INVALID_CONSTANT_NEGATE_TYPE,
INVALID_CONSTANT_NOT_TYPE,
INVALID_CONSTANT_STRING_ADD_TYPE,
INVALID_CONSTANT_NUM_ADD_TYPE,
INVALID_CONSTANT_STRING_LENGTH_TYPE,
INVALID_CONSTANT_SHIFT,
INVALID_FROM_ENVIRONMENT_NAME_TYPE,
INVALID_INT_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE,
INVALID_LOGICAL_AND_OPERAND_TYPE,
INVALID_LOGICAL_OR_OPERAND_TYPE,
INVALID_METADATA,
INVALID_METADATA_GENERIC,
INVALID_PACKAGE_CONFIG,
INVALID_PACKAGE_URI,
INVALID_STRING_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE,
JS_INTEROP_FIELD_NOT_SUPPORTED,
JS_INTEROP_NON_EXTERNAL_MEMBER,
JS_OBJECT_LITERAL_CONSTRUCTOR_WITH_POSITIONAL_ARGUMENTS,
JS_PLACEHOLDER_CAPTURE,
LIBRARY_NOT_FOUND,
MIRRORS_LIBRARY_NOT_SUPPORT_WITH_CFE,
MISSING_EXPRESSION_IN_THROW,
NATIVE_NON_INSTANCE_IN_NON_NATIVE_CLASS,
NO_SUCH_SUPER_MEMBER,
NON_NATIVE_EXTERNAL,
NOT_A_COMPILE_TIME_CONSTANT,
NOT_ASSIGNABLE,
PLEASE_REPORT_THE_CRASH,
PREAMBLE,
RETHROW_OUTSIDE_CATCH,
RETURN_IN_GENERATIVE_CONSTRUCTOR,
RETURN_IN_GENERATOR,
RUNTIME_TYPE_TO_STRING,
STRING_EXPECTED,
UNDEFINED_GETTER,
UNDEFINED_INSTANCE_GETTER_BUT_SETTER,
UNDEFINED_METHOD,
UNDEFINED_OPERATOR,
UNDEFINED_SETTER,
UNDEFINED_STATIC_GETTER_BUT_SETTER,
UNDEFINED_STATIC_SETTER_BUT_GETTER,
UNDEFINED_SUPER_SETTER,
WRONG_ARGUMENT_FOR_JS,
WRONG_ARGUMENT_FOR_JS_FIRST,
WRONG_ARGUMENT_FOR_JS_SECOND,
@ -143,174 +84,80 @@ class MessageTemplate {
///
/// The map is complete mapping from [MessageKind] to their corresponding
/// [MessageTemplate].
// The key type is a union of MessageKind and SharedMessageKind.
static final Map<dynamic, MessageTemplate> TEMPLATES = <dynamic,
MessageTemplate>{}
..addAll(shared_messages.TEMPLATES)
..addAll(const <MessageKind, MessageTemplate>{
/// Do not use this. It is here for legacy and debugging. It violates item
/// 4 of the guide lines for error messages in the beginning of the file.
MessageKind.GENERIC: MessageTemplate(MessageKind.GENERIC, '#{text}'),
static const Map<MessageKind, MessageTemplate> TEMPLATES = {
/// Do not use this. It is here for legacy and debugging. It violates item
/// 4 of the guide lines for error messages in the beginning of the file.
MessageKind.GENERIC: MessageTemplate(MessageKind.GENERIC, '#{text}'),
MessageKind.CANNOT_RESOLVE: MessageTemplate(
MessageKind.CANNOT_RESOLVE, "Cannot resolve '#{name}'."),
MessageKind.STRING_EXPECTED: MessageTemplate(MessageKind.STRING_EXPECTED,
"Expected a 'String', but got an instance of '#{type}'."),
MessageKind.NOT_A_COMPILE_TIME_CONSTANT: MessageTemplate(
MessageKind.NOT_A_COMPILE_TIME_CONSTANT,
"Not a compile-time constant."),
MessageKind.JS_PLACEHOLDER_CAPTURE: MessageTemplate(
MessageKind.JS_PLACEHOLDER_CAPTURE,
"JS code must not use '#' placeholders inside functions.",
howToFix: "Use an immediately called JavaScript function to capture the"
" the placeholder values as JavaScript function parameters."),
MessageKind.CYCLIC_COMPILE_TIME_CONSTANTS: MessageTemplate(
MessageKind.CYCLIC_COMPILE_TIME_CONSTANTS,
"Cycle in the compile-time constant computation."),
MessageKind.WRONG_ARGUMENT_FOR_JS: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS,
"JS expression must take two or more arguments."),
MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER: MessageTemplate(
MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER,
"Cannot resolve setter."),
MessageKind.WRONG_ARGUMENT_FOR_JS_FIRST: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS_FIRST,
"JS expression must take two or more arguments."),
MessageKind.STRING_EXPECTED: MessageTemplate(MessageKind.STRING_EXPECTED,
"Expected a 'String', but got an instance of '#{type}'."),
MessageKind.WRONG_ARGUMENT_FOR_JS_SECOND: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS_SECOND,
"JS second argument must be a string literal."),
MessageKind.JS_INTEROP_NON_EXTERNAL_MEMBER: MessageTemplate(
MessageKind.JS_INTEROP_NON_EXTERNAL_MEMBER,
"Js-interop members must be 'external'."),
MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT,
"Argument for 'JS_INTERCEPTOR_CONSTANT' must be a type constant."),
MessageKind.IMPLICIT_JS_INTEROP_FIELD_NOT_SUPPORTED: MessageTemplate(
MessageKind.IMPLICIT_JS_INTEROP_FIELD_NOT_SUPPORTED,
"Fields in js-interop classes are not supported.",
howToFix: "Try replacing the field with an "
"external getter and/or setter."),
MessageKind.JS_INTEROP_FIELD_NOT_SUPPORTED: MessageTemplate(
MessageKind.JS_INTEROP_FIELD_NOT_SUPPORTED,
"Field can't be marked as js-interop.",
howToFix: "Try replacing the field with an "
"external getter and/or setter."),
MessageKind.LIBRARY_NOT_FOUND: MessageTemplate(
MessageKind.LIBRARY_NOT_FOUND, "Library not found '#{resolvedUri}'."),
MessageKind.INVALID_PACKAGE_CONFIG: MessageTemplate(
MessageKind.INVALID_PACKAGE_CONFIG,
"""Package config file '#{uri}' is invalid.
#{exception}""",
howToFix: DONT_KNOW_HOW_TO_FIX),
MessageKind.INVALID_PACKAGE_URI: MessageTemplate(
MessageKind.INVALID_PACKAGE_URI,
"'#{uri}' is not a valid package URI (#{exception}).",
howToFix: DONT_KNOW_HOW_TO_FIX,
examples: [
"""
// can't have a 'top level' package URI
import 'package:foo.dart';
main() {}
""",
"""
// can't have 2 slashes
import 'package://foo/foo.dart';
main() {}
""",
"""
// package name must be valid
import 'package:not\valid/foo.dart';
main() {}
"""
]),
MessageKind.JS_PLACEHOLDER_CAPTURE: MessageTemplate(
MessageKind.JS_PLACEHOLDER_CAPTURE,
"JS code must not use '#' placeholders inside functions.",
howToFix:
"Use an immediately called JavaScript function to capture the"
" the placeholder values as JavaScript function parameters."),
MessageKind.WRONG_ARGUMENT_FOR_JS: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS,
"JS expression must take two or more arguments."),
MessageKind.WRONG_ARGUMENT_FOR_JS_FIRST: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS_FIRST,
"JS expression must take two or more arguments."),
MessageKind.WRONG_ARGUMENT_FOR_JS_SECOND: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS_SECOND,
"JS second argument must be a string literal."),
MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT: MessageTemplate(
MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT,
"Argument for 'JS_INTERCEPTOR_CONSTANT' must be a type constant."),
MessageKind.ABSTRACT_GETTER: MessageTemplate(
MessageKind.ABSTRACT_GETTER,
"The getter '#{name}' has no implementation in "
"class '#{class}'.",
howToFix: "Try adding a body to '#{name}' or declaring "
"'#{class}' to be 'abstract'.",
examples: [
"""
MessageKind.ABSTRACT_GETTER: MessageTemplate(
MessageKind.ABSTRACT_GETTER,
"The getter '#{name}' has no implementation in "
"class '#{class}'.",
howToFix: "Try adding a body to '#{name}' or declaring "
"'#{class}' to be 'abstract'.",
examples: [
"""
class Class {
get getter;
}
main() => new Class();
"""
]),
]),
MessageKind.INVALID_METADATA: MessageTemplate(
MessageKind.INVALID_METADATA,
"A metadata annotation must be either a reference to a compile-time "
"constant variable or a call to a constant constructor.",
howToFix:
"Try using a different constant value or referencing it through a "
"constant variable.",
examples: ['@Object main() {}', '@print main() {}']),
MessageKind.INVALID_METADATA: MessageTemplate(
MessageKind.INVALID_METADATA,
"A metadata annotation must be either a reference to a compile-time "
"constant variable or a call to a constant constructor.",
howToFix:
"Try using a different constant value or referencing it through a "
"constant variable.",
examples: ['@Object main() {}', '@print main() {}']),
MessageKind.INVALID_METADATA_GENERIC: MessageTemplate(
MessageKind.INVALID_METADATA_GENERIC,
"A metadata annotation using a constant constructor cannot use type "
"arguments.",
howToFix:
"Try removing the type arguments or referencing the constant "
"through a constant variable.",
examples: [
'''
MessageKind.INVALID_METADATA_GENERIC: MessageTemplate(
MessageKind.INVALID_METADATA_GENERIC,
"A metadata annotation using a constant constructor cannot use type "
"arguments.",
howToFix: "Try removing the type arguments or referencing the constant "
"through a constant variable.",
examples: [
'''
class C<T> {
const C();
}
@C<int>() main() {}
'''
]),
]),
MessageKind.EQUAL_MAP_ENTRY_KEY: MessageTemplate(
MessageKind.EQUAL_MAP_ENTRY_KEY,
"An entry with the same key already exists in the map.",
howToFix:
"Try removing the previous entry or changing the key in one "
"of the entries.",
examples: [
"""
main() {
var m = const {'foo': 1, 'foo': 2};
}"""
]),
MessageKind.COMPILER_CRASHED: MessageTemplate(MessageKind.COMPILER_CRASHED,
"The compiler crashed when compiling this element."),
MessageKind.EQUAL_SET_ENTRY: MessageTemplate(
MessageKind.EQUAL_SET_ENTRY, "An entry appears twice in the set.",
howToFix: "Try removing one of the entries.",
examples: [
"""
main() {
var m = const {'foo', 'bar', 'foo'};
}"""
]),
MessageKind.COMPILER_CRASHED: MessageTemplate(
MessageKind.COMPILER_CRASHED,
"The compiler crashed when compiling this element."),
MessageKind.PLEASE_REPORT_THE_CRASH:
MessageTemplate(MessageKind.PLEASE_REPORT_THE_CRASH, '''
MessageKind.PLEASE_REPORT_THE_CRASH:
MessageTemplate(MessageKind.PLEASE_REPORT_THE_CRASH, '''
The compiler is broken.
When compiling the above element, the compiler crashed. It is not
@ -330,221 +177,77 @@ Please include the following information:
below as well as the source location above).
'''),
MessageKind.HIDDEN_WARNINGS_HINTS: MessageTemplate(
MessageKind.HIDDEN_WARNINGS_HINTS,
"#{warnings} warning(s) and #{hints} hint(s) suppressed in #{uri}."),
MessageKind.HIDDEN_WARNINGS_HINTS: MessageTemplate(
MessageKind.HIDDEN_WARNINGS_HINTS,
"#{warnings} warning(s) and #{hints} hint(s) suppressed in #{uri}."),
MessageKind.HIDDEN_WARNINGS: MessageTemplate(MessageKind.HIDDEN_WARNINGS,
"#{warnings} warning(s) suppressed in #{uri}."),
MessageKind.HIDDEN_WARNINGS: MessageTemplate(MessageKind.HIDDEN_WARNINGS,
"#{warnings} warning(s) suppressed in #{uri}."),
MessageKind.HIDDEN_HINTS: MessageTemplate(
MessageKind.HIDDEN_HINTS, "#{hints} hint(s) suppressed in #{uri}."),
MessageKind.HIDDEN_HINTS: MessageTemplate(
MessageKind.HIDDEN_HINTS, "#{hints} hint(s) suppressed in #{uri}."),
MessageKind.PREAMBLE: MessageTemplate(
MessageKind.PREAMBLE,
"When run on the command-line, the compiled output might"
" require a preamble file located in:\n"
" <sdk>/lib/_internal/js_runtime/lib/preambles."),
MessageKind.PREAMBLE: MessageTemplate(
MessageKind.PREAMBLE,
"When run on the command-line, the compiled output might"
" require a preamble file located in:\n"
" <sdk>/lib/_internal/js_runtime/lib/preambles."),
MessageKind.INVALID_CONSTANT_CONDITIONAL_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_CONDITIONAL_TYPE,
"`#{constant}` of type '#{type}' is not a valid constant condition. "
"Must be a value of type 'bool'."),
MessageKind.DIRECTLY_THROWING_NSM: MessageTemplate(
MessageKind.DIRECTLY_THROWING_NSM,
"This 'noSuchMethod' implementation is guaranteed to throw an "
"exception. The generated code will be smaller if it is "
"rewritten.",
howToFix: "Rewrite to "
"'noSuchMethod(Invocation i) => super.noSuchMethod(i);'."),
MessageKind.INVALID_CONSTANT_INTERPOLATION_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_INTERPOLATION_TYPE,
"`#{constant}` of type '#{type}' is not valid in constant string "
"interpolation. Must be a value of type 'bool', 'int', 'double', "
"or 'String'."),
MessageKind.COMPLEX_THROWING_NSM: MessageTemplate(
MessageKind.COMPLEX_THROWING_NSM,
"This 'noSuchMethod' implementation is guaranteed to throw an "
"exception. The generated code will be smaller and the compiler "
"will be able to perform more optimizations if it is rewritten.",
howToFix: "Rewrite to "
"'noSuchMethod(Invocation i) => super.noSuchMethod(i);'."),
MessageKind.INVALID_CONSTANT_BINARY_PRIMITIVE_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_BINARY_PRIMITIVE_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant binary #{operator} expression. Must be a value of type "
"'bool', 'int', 'double', 'String', or 'Null'."),
MessageKind.COMPLEX_RETURNING_NSM: MessageTemplate(
MessageKind.COMPLEX_RETURNING_NSM,
"Overriding 'noSuchMethod' causes the compiler to generate "
"more code and prevents the compiler from doing some optimizations.",
howToFix: "Consider removing this 'noSuchMethod' implementation."),
MessageKind.INVALID_CONSTANT_STRING_ADD_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_STRING_ADD_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant binary + expression on 'String'. Must be a value of type "
"'String'."),
MessageKind.RUNTIME_TYPE_TO_STRING: MessageTemplate(
MessageKind.RUNTIME_TYPE_TO_STRING,
"Using '.runtimeType.toString()' causes the compiler to generate "
"more code because it needs to preserve type arguments on "
"generic classes, even if they are not necessary elsewhere.",
howToFix: "If used only for debugging, consider using option "
"${Flags.laxRuntimeTypeToString} to reduce the code size "
"impact."),
MessageKind.INVALID_CONSTANT_STRING_LENGTH_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_STRING_LENGTH_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand for a "
".length expression. Must be a value of type 'String'."),
MessageKind.NON_NATIVE_EXTERNAL: MessageTemplate(
MessageKind.NON_NATIVE_EXTERNAL,
"Non-native external members must be js-interop.",
howToFix: "Try removing the 'external' keyword, making it 'native', or "
"annotating the function as a js-interop function."),
MessageKind.INVALID_CONSTANT_SHIFT: MessageTemplate(
MessageKind.INVALID_CONSTANT_SHIFT,
"Shift amount must be non-negative in "
"`#{left} #{operator} #{right}`."),
MessageKind.NATIVE_NON_INSTANCE_IN_NON_NATIVE_CLASS: MessageTemplate(
MessageKind.NATIVE_NON_INSTANCE_IN_NON_NATIVE_CLASS,
"Native non-instance members are only allowed in native classes."),
MessageKind.INVALID_CONSTANT_DIV: MessageTemplate(
MessageKind.INVALID_CONSTANT_DIV,
"Divisor must be non-zero in `#{left} #{operator} #{right}`."),
MessageKind.INVALID_CONSTANT_NUM_ADD_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_NUM_ADD_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant binary + expression on 'num'. Must be a value of type "
"'int' or 'double'."),
MessageKind.INVALID_CONSTANT_CAST: MessageTemplate(
MessageKind.INVALID_CONSTANT_CAST,
"`#{constant}` of type '#{type}' is not a subtype of #{castType}."),
MessageKind.INVALID_CONSTANT_ADD_TYPES: MessageTemplate(
MessageKind.INVALID_CONSTANT_ADD_TYPES,
"`#{leftConstant}` of type '#{leftType}' and "
"`#{rightConstant}` of type '#{rightType}' are not valid operands "
"of a constant binary + expression. Must both be either of "
"type 'String', or of types 'int' or 'double'."),
MessageKind.INVALID_CONSTANT_BINARY_NUM_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_BINARY_NUM_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant binary #{operator} expression. Must be a value of type "
"'int' or 'double'."),
MessageKind.INVALID_CONSTANT_BINARY_INT_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_BINARY_INT_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant binary #{operator} expression. Must be a value of type "
"'int'."),
MessageKind.INVALID_CONSTANT_NOT_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_NOT_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant unary #{operator} expression. Must be a value of type "
"'bool'."),
MessageKind.INVALID_CONSTANT_NEGATE_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_NEGATE_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant unary #{operator} expression. Must be a value of type "
"'int' or 'double'."),
MessageKind.INVALID_CONSTANT_COMPLEMENT_TYPE: MessageTemplate(
MessageKind.INVALID_CONSTANT_COMPLEMENT_TYPE,
"`#{constant}` of type '#{type}' is not a valid operand of a "
"constant unary #{operator} expression. Must be a value of type "
"'int'."),
MessageKind.INVALID_CONSTANT_INDEX: MessageTemplate(
MessageKind.INVALID_CONSTANT_INDEX,
"Index expressions are not allowed in constant expressions."),
MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE: MessageTemplate(
MessageKind.INVALID_FROM_ENVIRONMENT_NAME_TYPE,
"`#{constant}` of type '#{type}' is not a valid environment name "
"constant. Must be a value of type 'String'."),
MessageKind.INVALID_BOOL_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE:
MessageTemplate(
MessageKind.INVALID_BOOL_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE,
"`#{constant}` of type '#{type}' is not a valid "
"`bool.fromEnvironment` default value constant. "
"Must be a value of type 'bool' or `null`."),
MessageKind.INVALID_INT_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE:
MessageTemplate(
MessageKind.INVALID_INT_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE,
"`#{constant}` of type '#{type}' is not a valid "
"`int.fromEnvironment` default value constant. "
"Must be a value of type 'int' or `null`."),
MessageKind.INVALID_STRING_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE:
MessageTemplate(
MessageKind.INVALID_STRING_FROM_ENVIRONMENT_DEFAULT_VALUE_TYPE,
"`#{constant}` of type '#{type}' is not a valid "
"`String.fromEnvironment` default value constant. "
"Must be a value of type 'String' or `null`."),
MessageKind.INVALID_LOGICAL_AND_OPERAND_TYPE: MessageTemplate(
MessageKind.INVALID_LOGICAL_AND_OPERAND_TYPE,
"`#{constant}` of type '#{type}' is not a valid logical and operand. "
"Must be a value of type 'bool'."),
MessageKind.INVALID_LOGICAL_OR_OPERAND_TYPE: MessageTemplate(
MessageKind.INVALID_LOGICAL_OR_OPERAND_TYPE,
"`#{constant}` of type '#{type}' is not a valid logical or operand. "
"Must be a value of type 'bool'."),
MessageKind.INVALID_CONSTANT_CONSTRUCTOR: MessageTemplate(
MessageKind.INVALID_CONSTANT_CONSTRUCTOR,
"Constructor '#{constructorName}' is not a valid constant "
"constructor."),
MessageKind.INVALID_ASSERT_VALUE: MessageTemplate(
MessageKind.INVALID_ASSERT_VALUE, "Assertion '#{assertion}' failed."),
MessageKind.INVALID_ASSERT_VALUE_MESSAGE: MessageTemplate(
MessageKind.INVALID_ASSERT_VALUE_MESSAGE,
"Assertion failed: #{message}"),
MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_WITH_CFE:
MessageTemplate(MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_WITH_CFE, """
dart2js no longer supports the dart:mirrors library.
APIs from this library will throw a runtime error at this time, but they will
become a compile-time error in the future."""),
MessageKind.DIRECTLY_THROWING_NSM: MessageTemplate(
MessageKind.DIRECTLY_THROWING_NSM,
"This 'noSuchMethod' implementation is guaranteed to throw an "
"exception. The generated code will be smaller if it is "
"rewritten.",
howToFix: "Rewrite to "
"'noSuchMethod(Invocation i) => super.noSuchMethod(i);'."),
MessageKind.COMPLEX_THROWING_NSM: MessageTemplate(
MessageKind.COMPLEX_THROWING_NSM,
"This 'noSuchMethod' implementation is guaranteed to throw an "
"exception. The generated code will be smaller and the compiler "
"will be able to perform more optimizations if it is rewritten.",
howToFix: "Rewrite to "
"'noSuchMethod(Invocation i) => super.noSuchMethod(i);'."),
MessageKind.COMPLEX_RETURNING_NSM: MessageTemplate(
MessageKind.COMPLEX_RETURNING_NSM,
"Overriding 'noSuchMethod' causes the compiler to generate "
"more code and prevents the compiler from doing some optimizations.",
howToFix: "Consider removing this 'noSuchMethod' implementation."),
MessageKind.RUNTIME_TYPE_TO_STRING: MessageTemplate(
MessageKind.RUNTIME_TYPE_TO_STRING,
"Using '.runtimeType.toString()' causes the compiler to generate "
"more code because it needs to preserve type arguments on "
"generic classes, even if they are not necessary elsewhere.",
howToFix: "If used only for debugging, consider using option "
"${Flags.laxRuntimeTypeToString} to reduce the code size "
"impact."),
MessageKind.NON_NATIVE_EXTERNAL: MessageTemplate(
MessageKind.NON_NATIVE_EXTERNAL,
"Non-native external members must be js-interop.",
howToFix:
"Try removing the 'external' keyword, making it 'native', or "
"annotating the function as a js-interop function."),
MessageKind.NATIVE_NON_INSTANCE_IN_NON_NATIVE_CLASS: MessageTemplate(
MessageKind.NATIVE_NON_INSTANCE_IN_NON_NATIVE_CLASS,
"Native non-instance members are only allowed in native classes."),
// TODO(32557): Remove these when issue 32557 is fixed.
MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS: MessageTemplate(
MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS,
"'case' expression type '#{type}' overrides 'operator =='."),
MessageKind.SWITCH_CASE_FORBIDDEN: MessageTemplate(
MessageKind.SWITCH_CASE_FORBIDDEN,
"'case' expression may not be of type '#{type}'."),
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL: MessageTemplate(
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL,
"'case' expressions do not all have type '#{type}'."),
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE: MessageTemplate(
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE,
"'case' expression of type '#{type}'."),
}); // End of TEMPLATES.
// TODO(32557): Remove these when issue 32557 is fixed.
MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS: MessageTemplate(
MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS,
"'case' expression type '#{type}' overrides 'operator =='."),
MessageKind.SWITCH_CASE_FORBIDDEN: MessageTemplate(
MessageKind.SWITCH_CASE_FORBIDDEN,
"'case' expression may not be of type '#{type}'."),
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL: MessageTemplate(
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL,
"'case' expressions do not all have type '#{type}'."),
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE: MessageTemplate(
MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE,
"'case' expression of type '#{type}'."),
}; // End of TEMPLATES.
@override
String toString() => template;