Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: pkg/compiler/lib/src/warnings.dart

Issue 1277143002: Rename warnings.dart to messages.dart. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/messages.dart ('k') | tests/compiler/dart2js/analyze_only_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5
6 /**
7 * The messages in this file should meet the following guide lines:
8 *
9 * 1. The message should be a complete sentence starting with an uppercase
10 * letter, and ending with a period.
11 *
12 * 2. Reserved words and embedded identifiers should be in single quotes, so
13 * prefer double quotes for the complete message. For example, "The
14 * class '#{className}' can't use 'super'." Notice that the word 'class' in the
15 * preceding message is not quoted as it refers to the concept 'class', not the
16 * reserved word. On the other hand, 'super' refers to the reserved word. Do
17 * not quote 'null' and numeric literals.
18 *
19 * 3. Do not try to compose messages, as it can make translating them hard.
20 *
21 * 4. Try to keep the error messages short, but informative.
22 *
23 * 5. Use simple words and terminology, assume the reader of the message
24 * doesn't have an advanced degree in math, and that English is not the
25 * reader's native language. Do not assume any formal computer science
26 * training. For example, do not use Latin abbreviations (prefer "that is" over
27 * "i.e.", and "for example" over "e.g."). Also avoid phrases such as "if and
28 * only if" and "iff", that level of precision is unnecessary.
29 *
30 * 6. Prefer contractions when they are in common use, for example, prefer
31 * "can't" over "cannot". Using "cannot", "must not", "shall not", etc. is
32 * off-putting to people new to programming.
33 *
34 * 7. Use common terminology, preferably from the Dart Language
35 * Specification. This increases the user's chance of finding a good
36 * explanation on the web.
37 *
38 * 8. Do not try to be cute or funny. It is extremely frustrating to work on a
39 * product that crashes with a "tongue-in-cheek" message, especially if you did
40 * not want to use this product to begin with.
41 *
42 * 9. Do not lie, that is, do not write error messages containing phrases like
43 * "can't happen". If the user ever saw this message, it would be a
44 * lie. Prefer messages like: "Internal error: This function should not be
45 * called when 'x' is null.".
46 *
47 * 10. Prefer to not use imperative tone. That is, the message should not sound
48 * accusing or like it is ordering the user around. The computer should
49 * describe the problem, not criticize for violating the specification.
50 *
51 * Other things to keep in mind:
52 *
53 * An INFO message should always be preceded by a non-INFO message, and the
54 * INFO messages are additional details about the preceding non-INFO
55 * message. For example, consider duplicated elements. First report a WARNING
56 * or ERROR about the duplicated element, and then report an INFO about the
57 * location of the existing element.
58 *
59 * Generally, we want to provide messages that consists of three sentences:
60 * 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we
61 * combine the first two in [template] and the last in [howToFix].
62 */
63
64 library dart2js.messages;
65
66 import 'dart2jslib.dart';
67 import 'scanner/scannerlib.dart';
68
69 const DONT_KNOW_HOW_TO_FIX = "Computer says no!";
70
71 /// Keys for the [MessageTemplate]s.
72 enum MessageKind {
73 ABSTRACT_CLASS_INSTANTIATION,
74 ABSTRACT_GETTER,
75 ABSTRACT_METHOD,
76 ABSTRACT_SETTER,
77 ACCESSED_IN_CLOSURE,
78 ACCESSED_IN_CLOSURE_HERE,
79 ADDITIONAL_ARGUMENT,
80 ADDITIONAL_TYPE_ARGUMENT,
81 ALREADY_INITIALIZED,
82 AMBIGUOUS_LOCATION,
83 AMBIGUOUS_REEXPORT,
84 ASSERT_IS_GIVEN_NAMED_ARGUMENTS,
85 ASSIGNING_FINAL_FIELD_IN_SUPER,
86 ASSIGNING_METHOD,
87 ASSIGNING_METHOD_IN_SUPER,
88 ASSIGNING_TYPE,
89 ASYNC_KEYWORD_AS_IDENTIFIER,
90 ASYNC_MODIFIER_ON_ABSTRACT_METHOD,
91 ASYNC_MODIFIER_ON_CONSTRUCTOR,
92 ASYNC_MODIFIER_ON_SETTER,
93 AWAIT_MEMBER_NOT_FOUND,
94 AWAIT_MEMBER_NOT_FOUND_IN_CLOSURE,
95 BAD_INPUT_CHARACTER,
96 BEFORE_TOP_LEVEL,
97 BINARY_OPERATOR_BAD_ARITY,
98 BODY_EXPECTED,
99 CALL_NOT_SUPPORTED_ON_NATIVE_CLASS,
100 CANNOT_EXTEND,
101 CANNOT_EXTEND_ENUM,
102 CANNOT_EXTEND_MALFORMED,
103 CANNOT_FIND_CONSTRUCTOR,
104 CANNOT_IMPLEMENT,
105 CANNOT_IMPLEMENT_ENUM,
106 CANNOT_IMPLEMENT_MALFORMED,
107 CANNOT_INSTANTIATE_ENUM,
108 CANNOT_INSTANTIATE_TYPE_VARIABLE,
109 CANNOT_INSTANTIATE_TYPEDEF,
110 CANNOT_MIXIN,
111 CANNOT_MIXIN_ENUM,
112 CANNOT_MIXIN_MALFORMED,
113 CANNOT_OVERRIDE_FIELD_WITH_METHOD,
114 CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT,
115 CANNOT_OVERRIDE_GETTER_WITH_METHOD,
116 CANNOT_OVERRIDE_GETTER_WITH_METHOD_CONT,
117 CANNOT_OVERRIDE_METHOD_WITH_FIELD,
118 CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT,
119 CANNOT_OVERRIDE_METHOD_WITH_GETTER,
120 CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT,
121 CANNOT_RESOLVE,
122 CANNOT_RESOLVE_AWAIT,
123 CANNOT_RESOLVE_AWAIT_IN_CLOSURE,
124 CANNOT_RESOLVE_CONSTRUCTOR,
125 CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT,
126 CANNOT_RESOLVE_GETTER,
127 CANNOT_RESOLVE_IN_INITIALIZER,
128 CANNOT_RESOLVE_SETTER,
129 CANNOT_RESOLVE_TYPE,
130 CANNOT_RETURN_FROM_CONSTRUCTOR,
131 CLASS_NAME_EXPECTED,
132 COMPILER_CRASHED,
133 COMPLEX_RETURNING_NSM,
134 COMPLEX_THROWING_NSM,
135 CONSIDER_ANALYZE_ALL,
136 CONST_CALLS_NON_CONST,
137 CONST_CALLS_NON_CONST_FOR_IMPLICIT,
138 CONST_CONSTRUCTOR_HAS_BODY,
139 CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS,
140 CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR,
141 CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD,
142 CONST_MAP_KEY_OVERRIDES_EQUALS,
143 CONST_WITHOUT_INITIALIZER,
144 CONSTRUCTOR_CALL_EXPECTED,
145 CONSTRUCTOR_IS_NOT_CONST,
146 CONSTRUCTOR_WITH_RETURN_TYPE,
147 CYCLIC_CLASS_HIERARCHY,
148 CYCLIC_COMPILE_TIME_CONSTANTS,
149 CYCLIC_REDIRECTING_FACTORY,
150 CYCLIC_TYPE_VARIABLE,
151 CYCLIC_TYPEDEF,
152 CYCLIC_TYPEDEF_ONE,
153 DART_EXT_NOT_SUPPORTED,
154 DEFERRED_COMPILE_TIME_CONSTANT,
155 DEFERRED_COMPILE_TIME_CONSTANT_CONSTRUCTION,
156 DEFERRED_LIBRARY_DART_2_DART,
157 DEFERRED_LIBRARY_DUPLICATE_PREFIX,
158 DEFERRED_LIBRARY_WITHOUT_PREFIX,
159 DEFERRED_OLD_SYNTAX,
160 DEFERRED_TYPE_ANNOTATION,
161 DEPRECATED_TYPEDEF_MIXIN_SYNTAX,
162 DIRECTLY_THROWING_NSM,
163 DUPLICATE_DEFINITION,
164 DUPLICATE_EXPORT,
165 DUPLICATE_EXPORT_CONT,
166 DUPLICATE_EXPORT_DECL,
167 DUPLICATE_EXTENDS_IMPLEMENTS,
168 DUPLICATE_IMPLEMENTS,
169 DUPLICATE_IMPORT,
170 DUPLICATE_INITIALIZER,
171 DUPLICATE_LABEL,
172 DUPLICATE_SUPER_INITIALIZER,
173 DUPLICATE_TYPE_VARIABLE_NAME,
174 DUPLICATED_LIBRARY_NAME,
175 DUPLICATED_LIBRARY_RESOURCE,
176 DUPLICATED_PART_OF,
177 DUPLICATED_RESOURCE,
178 EMPTY_CATCH_DECLARATION,
179 EMPTY_ENUM_DECLARATION,
180 EQUAL_MAP_ENTRY_KEY,
181 EXISTING_DEFINITION,
182 EXISTING_LABEL,
183 EXPECTED_IDENTIFIER_NOT_RESERVED_WORD,
184 EXPONENT_MISSING,
185 EXPORT_BEFORE_PARTS,
186 EXTERNAL_WITH_BODY,
187 EXTRA_CATCH_DECLARATION,
188 EXTRA_FORMALS,
189 EXTRANEOUS_MODIFIER,
190 EXTRANEOUS_MODIFIER_REPLACE,
191 FACTORY_REDIRECTION_IN_NON_FACTORY,
192 FINAL_FUNCTION_TYPE_PARAMETER,
193 FINAL_WITHOUT_INITIALIZER,
194 FORMAL_DECLARED_CONST,
195 FORMAL_DECLARED_STATIC,
196 FUNCTION_TYPE_FORMAL_WITH_DEFAULT,
197 FUNCTION_WITH_INITIALIZER,
198 GENERIC,
199 GETTER_MISMATCH,
200 GETTER_NOT_FOUND,
201 HEX_DIGIT_EXPECTED,
202 HIDDEN_HINTS,
203 HIDDEN_IMPLICIT_IMPORT,
204 HIDDEN_IMPORT,
205 HIDDEN_WARNINGS,
206 HIDDEN_WARNINGS_HINTS,
207 IF_NULL_ASSIGNING_TYPE,
208 ILLEGAL_CONST_FIELD_MODIFIER,
209 ILLEGAL_CONSTRUCTOR_MODIFIERS,
210 ILLEGAL_FINAL_METHOD_MODIFIER,
211 ILLEGAL_MIXIN_APPLICATION_MODIFIERS,
212 ILLEGAL_MIXIN_CONSTRUCTOR,
213 ILLEGAL_MIXIN_CYCLE,
214 ILLEGAL_MIXIN_OBJECT,
215 ILLEGAL_MIXIN_SUPER_USE,
216 ILLEGAL_MIXIN_SUPERCLASS,
217 ILLEGAL_MIXIN_WITH_SUPER,
218 ILLEGAL_SETTER_FORMALS,
219 ILLEGAL_STATIC,
220 ILLEGAL_SUPER_SEND,
221 IMPORT_BEFORE_PARTS,
222 IMPORT_EXPERIMENTAL_MIRRORS,
223 IMPORT_PART_OF,
224 IMPORTED_HERE,
225 INHERIT_GETTER_AND_METHOD,
226 INHERITED_EXPLICIT_GETTER,
227 INHERITED_IMPLICIT_GETTER,
228 INHERITED_METHOD,
229 INIT_STATIC_FIELD,
230 INITIALIZING_FORMAL_NOT_ALLOWED,
231 INSTANCE_STATIC_SAME_NAME,
232 INSTANCE_STATIC_SAME_NAME_CONT,
233 INTERNAL_LIBRARY,
234 INTERNAL_LIBRARY_FROM,
235 INVALID_ARGUMENT_AFTER_NAMED,
236 INVALID_AWAIT_FOR,
237 INVALID_BREAK,
238 INVALID_CASE_DEFAULT,
239 INVALID_CONSTRUCTOR_ARGUMENTS,
240 INVALID_CONSTRUCTOR_NAME,
241 INVALID_CONTINUE,
242 INVALID_FOR_IN,
243 INVALID_INITIALIZER,
244 INVALID_OVERRIDDEN_FIELD,
245 INVALID_OVERRIDDEN_GETTER,
246 INVALID_OVERRIDDEN_METHOD,
247 INVALID_OVERRIDDEN_SETTER,
248 INVALID_OVERRIDE_FIELD,
249 INVALID_OVERRIDE_FIELD_WITH_GETTER,
250 INVALID_OVERRIDE_FIELD_WITH_SETTER,
251 INVALID_OVERRIDE_GETTER,
252 INVALID_OVERRIDE_GETTER_WITH_FIELD,
253 INVALID_OVERRIDE_METHOD,
254 INVALID_OVERRIDE_SETTER,
255 INVALID_OVERRIDE_SETTER_WITH_FIELD,
256 INVALID_PACKAGE_URI,
257 INVALID_PARAMETER,
258 INVALID_RECEIVER_IN_INITIALIZER,
259 INVALID_SOURCE_FILE_LOCATION,
260 INVALID_SYMBOL,
261 INVALID_SYNC_MODIFIER,
262 INVALID_TYPE_VARIABLE_BOUND,
263 INVALID_UNNAMED_CONSTRUCTOR_NAME,
264 INVALID_URI,
265 INVALID_USE_OF_SUPER,
266 LIBRARY_NAME_MISMATCH,
267 LIBRARY_NOT_FOUND,
268 LIBRARY_TAG_MUST_BE_FIRST,
269 MAIN_NOT_A_FUNCTION,
270 MAIN_WITH_EXTRA_PARAMETER,
271 MALFORMED_STRING_LITERAL,
272 MEMBER_NOT_FOUND,
273 MEMBER_NOT_STATIC,
274 MEMBER_USES_CLASS_NAME,
275 METHOD_NOT_FOUND,
276 MINUS_OPERATOR_BAD_ARITY,
277 MIRROR_BLOAT,
278 MIRROR_IMPORT,
279 MIRROR_IMPORT_NO_USAGE,
280 MIRRORS_CANNOT_FIND_IN_ELEMENT,
281 MIRRORS_CANNOT_RESOLVE_IN_CURRENT_LIBRARY,
282 MIRRORS_CANNOT_RESOLVE_IN_LIBRARY,
283 MIRRORS_EXPECTED_STRING,
284 MIRRORS_EXPECTED_STRING_OR_LIST,
285 MIRRORS_EXPECTED_STRING_OR_TYPE,
286 MIRRORS_EXPECTED_STRING_TYPE_OR_LIST,
287 MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND,
288 MISSING_ARGUMENT,
289 MISSING_ENUM_CASES,
290 MISSING_FACTORY_KEYWORD,
291 MISSING_FORMALS,
292 MISSING_LIBRARY_NAME,
293 MISSING_MAIN,
294 MISSING_PART_OF_TAG,
295 MISSING_TOKEN_AFTER_THIS,
296 MISSING_TOKEN_BEFORE_THIS,
297 MISSING_TYPE_ARGUMENT,
298 MULTI_INHERITANCE,
299 NAMED_ARGUMENT_NOT_FOUND,
300 NAMED_FUNCTION_EXPRESSION,
301 NAMED_PARAMETER_WITH_EQUALS,
302 NATIVE_NOT_SUPPORTED,
303 NO_BREAK_TARGET,
304 NO_CATCH_NOR_FINALLY,
305 NO_CONTINUE_TARGET,
306 NO_INSTANCE_AVAILABLE,
307 NO_MATCHING_CONSTRUCTOR,
308 NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT,
309 NO_STATIC_OVERRIDE,
310 NO_STATIC_OVERRIDE_CONT,
311 NO_SUCH_LIBRARY_MEMBER,
312 NO_SUCH_METHOD_IN_NATIVE,
313 NO_SUCH_SUPER_MEMBER,
314 NO_SUPER_IN_STATIC,
315 NO_THIS_AVAILABLE,
316 NON_CONST_BLOAT,
317 NOT_A_COMPILE_TIME_CONSTANT,
318 NOT_A_FIELD,
319 NOT_A_PREFIX,
320 NOT_A_TYPE,
321 NOT_ASSIGNABLE,
322 NOT_CALLABLE,
323 NOT_INSTANCE_FIELD,
324 NOT_MORE_SPECIFIC,
325 NOT_MORE_SPECIFIC_SUBTYPE,
326 NOT_MORE_SPECIFIC_SUGGESTION,
327 NULL_NOT_ALLOWED,
328 ONLY_ONE_LIBRARY_TAG,
329 OPERATOR_NAMED_PARAMETERS,
330 OPERATOR_NOT_FOUND,
331 OPERATOR_OPTIONAL_PARAMETERS,
332 OPTIONAL_PARAMETER_IN_CATCH,
333 OVERRIDE_EQUALS_NOT_HASH_CODE,
334 PARAMETER_NAME_EXPECTED,
335 PARAMETER_WITH_MODIFIER_IN_CATCH,
336 PARAMETER_WITH_TYPE_IN_CATCH,
337 PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION,
338 PATCH_NO_GETTER,
339 PATCH_NO_SETTER,
340 PATCH_NON_CLASS,
341 PATCH_NON_CONSTRUCTOR,
342 PATCH_NON_EXISTING,
343 PATCH_NON_EXTERNAL,
344 PATCH_NON_FUNCTION,
345 PATCH_NON_GETTER,
346 PATCH_NON_SETTER,
347 PATCH_NONPATCHABLE,
348 PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH,
349 PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH,
350 PATCH_PARAMETER_MISMATCH,
351 PATCH_PARAMETER_TYPE_MISMATCH,
352 PATCH_POINT_TO_CLASS,
353 PATCH_POINT_TO_CONSTRUCTOR,
354 PATCH_POINT_TO_FUNCTION,
355 PATCH_POINT_TO_GETTER,
356 PATCH_POINT_TO_PARAMETER,
357 PATCH_POINT_TO_SETTER,
358 PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH,
359 PATCH_RETURN_TYPE_MISMATCH,
360 PLEASE_REPORT_THE_CRASH,
361 POSITIONAL_PARAMETER_WITH_EQUALS,
362 POTENTIAL_MUTATION,
363 POTENTIAL_MUTATION_HERE,
364 POTENTIAL_MUTATION_IN_CLOSURE,
365 POTENTIAL_MUTATION_IN_CLOSURE_HERE,
366 PREAMBLE,
367 PREFIX_AS_EXPRESSION,
368 PRIVATE_ACCESS,
369 PRIVATE_IDENTIFIER,
370 PRIVATE_NAMED_PARAMETER,
371 READ_SCRIPT_ERROR,
372 READ_SELF_ERROR,
373 REDIRECTING_CONSTRUCTOR_CYCLE,
374 REDIRECTING_CONSTRUCTOR_HAS_BODY,
375 REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER,
376 REDIRECTING_FACTORY_WITH_DEFAULT,
377 REFERENCE_IN_INITIALIZATION,
378 REQUIRED_PARAMETER_WITH_DEFAULT,
379 RETURN_IN_GENERATOR,
380 RETURN_NOTHING,
381 RETURN_VALUE_IN_VOID,
382 SETTER_MISMATCH,
383 SETTER_NOT_FOUND,
384 SETTER_NOT_FOUND_IN_SUPER,
385 STATIC_FUNCTION_BLOAT,
386 STRING_EXPECTED,
387 SUPER_INITIALIZER_IN_OBJECT,
388 SWITCH_CASE_FORBIDDEN,
389 SWITCH_CASE_TYPES_NOT_EQUAL,
390 SWITCH_CASE_TYPES_NOT_EQUAL_CASE,
391 SWITCH_CASE_VALUE_OVERRIDES_EQUALS,
392 TERNARY_OPERATOR_BAD_ARITY,
393 THIS_IS_THE_DECLARATION,
394 THIS_IS_THE_METHOD,
395 THIS_IS_THE_PART_OF_TAG,
396 THIS_PROPERTY,
397 THROW_WITHOUT_EXPRESSION,
398 TOP_LEVEL_VARIABLE_DECLARED_STATIC,
399 TYPE_ARGUMENT_COUNT_MISMATCH,
400 TYPE_VARIABLE_IN_CONSTANT,
401 TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
402 TYPEDEF_FORMAL_WITH_DEFAULT,
403 UNARY_OPERATOR_BAD_ARITY,
404 UNBOUND_LABEL,
405 UNIMPLEMENTED_EXPLICIT_GETTER,
406 UNIMPLEMENTED_EXPLICIT_SETTER,
407 UNIMPLEMENTED_GETTER,
408 UNIMPLEMENTED_GETTER_ONE,
409 UNIMPLEMENTED_IMPLICIT_GETTER,
410 UNIMPLEMENTED_IMPLICIT_SETTER,
411 UNIMPLEMENTED_METHOD,
412 UNIMPLEMENTED_METHOD_CONT,
413 UNIMPLEMENTED_METHOD_ONE,
414 UNIMPLEMENTED_SETTER,
415 UNIMPLEMENTED_SETTER_ONE,
416 UNMATCHED_TOKEN,
417 UNSUPPORTED_BANG_EQ_EQ,
418 UNSUPPORTED_EQ_EQ_EQ,
419 UNSUPPORTED_LITERAL_SYMBOL,
420 UNSUPPORTED_PREFIX_PLUS,
421 UNSUPPORTED_THROW_WITHOUT_EXP,
422 UNTERMINATED_COMMENT,
423 UNTERMINATED_STRING,
424 UNTERMINATED_TOKEN,
425 UNUSED_CLASS,
426 UNUSED_LABEL,
427 UNUSED_METHOD,
428 UNUSED_TYPEDEF,
429 VAR_FUNCTION_TYPE_PARAMETER,
430 VOID_EXPRESSION,
431 VOID_NOT_ALLOWED,
432 VOID_VARIABLE,
433 WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT,
434 WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT,
435 YIELDING_MODIFIER_ON_ARROW_BODY,
436 }
437
438 /// A message template for an error, warning, hint or info message generated
439 /// by the compiler. Each template is associated with a [MessageKind] that
440 /// uniquely identifies the message template.
441 // TODO(johnnniwinther): For Infos, consider adding a reference to the
442 // error/warning/hint that they belong to.
443 class MessageTemplate {
444 final MessageKind kind;
445
446 /// Should describe what is wrong and why.
447 final String template;
448
449 /// Should describe how to fix the problem. Elided when using --terse option.
450 final String howToFix;
451
452 /**
453 * Examples will be checked by
454 * tests/compiler/dart2js/message_kind_test.dart.
455 *
456 * An example is either a String containing the example source code or a Map
457 * from filenames to source code. In the latter case, the filename for the
458 * main library code must be 'main.dart'.
459 */
460 final List examples;
461
462 /// Additional options needed for the examples to work.
463 final List<String> options;
464
465 const MessageTemplate(
466 this.kind,
467 this.template,
468 {this.howToFix,
469 this.examples,
470 this.options: const <String>[]});
471
472 /// All templates used by the compiler.
473 ///
474 /// The map is complete mapping from [MessageKind] to their corresponding
475 /// [MessageTemplate].
476 static const Map<MessageKind, MessageTemplate> TEMPLATES =
477 const <MessageKind, MessageTemplate>{
478 /// Do not use this. It is here for legacy and debugging. It violates item
479 /// 4 of the guide lines for error messages in the beginning of the file.
480 MessageKind.GENERIC:
481 const MessageTemplate(MessageKind.GENERIC, '#{text}'),
482
483 MessageKind.NOT_ASSIGNABLE:
484 const MessageTemplate(MessageKind.NOT_ASSIGNABLE,
485 "'#{fromType}' is not assignable to '#{toType}'."),
486
487 MessageKind.VOID_EXPRESSION:
488 const MessageTemplate(MessageKind.VOID_EXPRESSION,
489 "Expression does not yield a value."),
490
491 MessageKind.VOID_VARIABLE:
492 const MessageTemplate(MessageKind.VOID_VARIABLE,
493 "Variable cannot be of type void."),
494
495 MessageKind.RETURN_VALUE_IN_VOID:
496 const MessageTemplate(MessageKind.RETURN_VALUE_IN_VOID,
497 "Cannot return value from void function."),
498
499 MessageKind.RETURN_NOTHING:
500 const MessageTemplate(MessageKind.RETURN_NOTHING,
501 "Value of type '#{returnType}' expected."),
502
503 MessageKind.MISSING_ARGUMENT:
504 const MessageTemplate(MessageKind.MISSING_ARGUMENT,
505 "Missing argument of type '#{argumentType}'."),
506
507 MessageKind.ADDITIONAL_ARGUMENT:
508 const MessageTemplate(MessageKind.ADDITIONAL_ARGUMENT,
509 "Additional argument."),
510
511 MessageKind.NAMED_ARGUMENT_NOT_FOUND:
512 const MessageTemplate(MessageKind.NAMED_ARGUMENT_NOT_FOUND,
513 "No named argument '#{argumentName}' found on method."),
514
515 MessageKind.MEMBER_NOT_FOUND:
516 const MessageTemplate(MessageKind.MEMBER_NOT_FOUND,
517 "No member named '#{memberName}' in class '#{className}'."),
518
519 MessageKind.AWAIT_MEMBER_NOT_FOUND:
520 const MessageTemplate(MessageKind.AWAIT_MEMBER_NOT_FOUND,
521 "No member named 'await' in class '#{className}'.",
522 howToFix: "Did you mean to add the 'async' marker "
523 "to '#{functionName}'?",
524 examples: const ["""
525 class A {
526 m() => await -3;
527 }
528 main() => new A().m();
529 """]),
530
531 MessageKind.AWAIT_MEMBER_NOT_FOUND_IN_CLOSURE:
532 const MessageTemplate(MessageKind.AWAIT_MEMBER_NOT_FOUND_IN_CLOSURE,
533 "No member named 'await' in class '#{className}'.",
534 howToFix: "Did you mean to add the 'async' marker "
535 "to the enclosing function?",
536 examples: const ["""
537 class A {
538 m() => () => await -3;
539 }
540 main() => new A().m();
541 """]),
542
543 MessageKind.METHOD_NOT_FOUND:
544 const MessageTemplate(MessageKind.METHOD_NOT_FOUND,
545 "No method named '#{memberName}' in class '#{className}'."),
546
547 MessageKind.OPERATOR_NOT_FOUND:
548 const MessageTemplate(MessageKind.OPERATOR_NOT_FOUND,
549 "No operator '#{memberName}' in class '#{className}'."),
550
551 MessageKind.SETTER_NOT_FOUND:
552 const MessageTemplate(MessageKind.SETTER_NOT_FOUND,
553 "No setter named '#{memberName}' in class '#{className}'."),
554
555 MessageKind.SETTER_NOT_FOUND_IN_SUPER:
556 const MessageTemplate(MessageKind.SETTER_NOT_FOUND_IN_SUPER,
557 "No setter named '#{name}' in superclass of '#{className}'."),
558
559 MessageKind.GETTER_NOT_FOUND:
560 const MessageTemplate(MessageKind.GETTER_NOT_FOUND,
561 "No getter named '#{memberName}' in class '#{className}'."),
562
563 MessageKind.NOT_CALLABLE:
564 const MessageTemplate(MessageKind.NOT_CALLABLE,
565 "'#{elementName}' is not callable."),
566
567 MessageKind.MEMBER_NOT_STATIC:
568 const MessageTemplate(MessageKind.MEMBER_NOT_STATIC,
569 "'#{className}.#{memberName}' is not static."),
570
571 MessageKind.NO_INSTANCE_AVAILABLE:
572 const MessageTemplate(MessageKind.NO_INSTANCE_AVAILABLE,
573 "'#{name}' is only available in instance methods."),
574
575 MessageKind.NO_THIS_AVAILABLE:
576 const MessageTemplate(MessageKind.NO_THIS_AVAILABLE,
577 "'this' is only available in instance methods."),
578
579 MessageKind.PRIVATE_ACCESS:
580 const MessageTemplate(MessageKind.PRIVATE_ACCESS,
581 "'#{name}' is declared private within library "
582 "'#{libraryName}'."),
583
584 MessageKind.THIS_IS_THE_DECLARATION:
585 const MessageTemplate(MessageKind.THIS_IS_THE_DECLARATION,
586 "This is the declaration of '#{name}'."),
587
588 MessageKind.THIS_IS_THE_METHOD:
589 const MessageTemplate(MessageKind.THIS_IS_THE_METHOD,
590 "This is the method declaration."),
591
592 MessageKind.CANNOT_RESOLVE:
593 const MessageTemplate(MessageKind.CANNOT_RESOLVE,
594 "Cannot resolve '#{name}'."),
595
596 MessageKind.CANNOT_RESOLVE_AWAIT:
597 const MessageTemplate(MessageKind.CANNOT_RESOLVE_AWAIT,
598 "Cannot resolve '#{name}'.",
599 howToFix: "Did you mean to add the 'async' marker "
600 "to '#{functionName}'?",
601 examples: const [
602 "main() => await -3;",
603 "foo() => await -3; main() => foo();"
604 ]),
605
606 MessageKind.CANNOT_RESOLVE_AWAIT_IN_CLOSURE:
607 const MessageTemplate(MessageKind.CANNOT_RESOLVE_AWAIT_IN_CLOSURE,
608 "Cannot resolve '#{name}'.",
609 howToFix: "Did you mean to add the 'async' marker "
610 "to the enclosing function?",
611 examples: const [
612 "main() { (() => await -3)(); }",
613 ]),
614
615 MessageKind.CANNOT_RESOLVE_IN_INITIALIZER:
616 const MessageTemplate(MessageKind.CANNOT_RESOLVE_IN_INITIALIZER,
617 "Cannot resolve '#{name}'. It would be implicitly looked up on this "
618 "instance, but instances are not available in initializers.",
619 howToFix: "Try correcting the unresolved reference or move the "
620 "initialization to a constructor body.",
621 examples: const ["""
622 class A {
623 var test = unresolvedName;
624 }
625 main() => new A();
626 """]),
627
628 MessageKind.CANNOT_RESOLVE_CONSTRUCTOR:
629 const MessageTemplate(MessageKind.CANNOT_RESOLVE_CONSTRUCTOR,
630 "Cannot resolve constructor '#{constructorName}'."),
631
632 MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT:
633 const MessageTemplate(
634 MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT,
635 "cannot resolve constructor '#{constructorName}' "
636 "for implicit super call.",
637 howToFix: "Try explicitly invoking a constructor of the super class",
638 examples: const ["""
639 class A {
640 A.foo() {}
641 }
642 class B extends A {
643 B();
644 }
645 main() => new B();
646 """]),
647
648 MessageKind.INVALID_UNNAMED_CONSTRUCTOR_NAME:
649 const MessageTemplate(MessageKind.INVALID_UNNAMED_CONSTRUCTOR_NAME,
650 "Unnamed constructor name must be '#{name}'."),
651
652 MessageKind.INVALID_CONSTRUCTOR_NAME:
653 const MessageTemplate(MessageKind.INVALID_CONSTRUCTOR_NAME,
654 "Constructor name must start with '#{name}'."),
655
656 MessageKind.CANNOT_RESOLVE_TYPE:
657 const MessageTemplate(MessageKind.CANNOT_RESOLVE_TYPE,
658 "Cannot resolve type '#{typeName}'."),
659
660 MessageKind.DUPLICATE_DEFINITION:
661 const MessageTemplate(MessageKind.DUPLICATE_DEFINITION,
662 "Duplicate definition of '#{name}'.",
663 howToFix: "Try to rename or remove this definition.",
664 examples: const ["""
665 class C {
666 void f() {}
667 int get f => 1;
668 }
669
670 main() {
671 new C();
672 }
673
674 """]),
675
676 MessageKind.EXISTING_DEFINITION:
677 const MessageTemplate(MessageKind.EXISTING_DEFINITION,
678 "Existing definition of '#{name}'."),
679
680 MessageKind.DUPLICATE_IMPORT:
681 const MessageTemplate(MessageKind.DUPLICATE_IMPORT,
682 "Duplicate import of '#{name}'."),
683
684 MessageKind.HIDDEN_IMPORT:
685 const MessageTemplate(MessageKind.HIDDEN_IMPORT,
686 "'#{name}' from library '#{hiddenUri}' is hidden by '#{name}' "
687 "from library '#{hidingUri}'.",
688 howToFix:
689 "Try adding 'hide #{name}' to the import of '#{hiddenUri}'.",
690 examples: const [
691 const {
692 'main.dart':
693 """
694 import 'dart:async'; // This imports a class Future.
695 import 'future.dart';
696
697 void main() => new Future();""",
698
699 'future.dart':
700 """
701 library future;
702
703 class Future {}"""},
704
705 const {
706 'main.dart':
707 """
708 import 'future.dart';
709 import 'dart:async'; // This imports a class Future.
710
711 void main() => new Future();""",
712
713 'future.dart':
714 """
715 library future;
716
717 class Future {}"""},
718
719 const {
720 'main.dart':
721 """
722 import 'export.dart';
723 import 'dart:async'; // This imports a class Future.
724
725 void main() => new Future();""",
726
727 'future.dart':
728 """
729 library future;
730
731 class Future {}""",
732
733 'export.dart':
734 """
735 library export;
736
737 export 'future.dart';"""},
738
739 const {
740 'main.dart':
741 """
742 import 'future.dart' as prefix;
743 import 'dart:async' as prefix; // This imports a class Future.
744
745 void main() => new prefix.Future();""",
746
747 'future.dart':
748 """
749 library future;
750
751 class Future {}"""}]),
752
753
754 MessageKind.HIDDEN_IMPLICIT_IMPORT:
755 const MessageTemplate(MessageKind.HIDDEN_IMPLICIT_IMPORT,
756 "'#{name}' from library '#{hiddenUri}' is hidden by '#{name}' "
757 "from library '#{hidingUri}'.",
758 howToFix: "Try adding an explicit "
759 "'import \"#{hiddenUri}\" hide #{name}'.",
760 examples: const [
761 const {
762 'main.dart':
763 """
764 // This hides the implicit import of class Type from dart:core.
765 import 'type.dart';
766
767 void main() => new Type();""",
768
769 'type.dart':
770 """
771 library type;
772
773 class Type {}"""},
774 const {
775 'conflictsWithDart.dart':
776 """
777 library conflictsWithDart;
778
779 class Duration {
780 static var x = 100;
781 }
782 """,
783
784 'conflictsWithDartAsWell.dart':
785 """
786 library conflictsWithDartAsWell;
787
788 class Duration {
789 static var x = 100;
790 }
791 """,
792
793 'main.dart':
794 r"""
795 library testDartConflicts;
796
797 import 'conflictsWithDart.dart';
798 import 'conflictsWithDartAsWell.dart';
799
800 main() {
801 print("Hail Caesar ${Duration.x}");
802 }
803 """}]),
804
805 MessageKind.DUPLICATE_EXPORT:
806 const MessageTemplate(MessageKind.DUPLICATE_EXPORT,
807 "Duplicate export of '#{name}'.",
808 howToFix: "Trying adding 'hide #{name}' to one of the exports.",
809 examples: const [const {
810 'main.dart': """
811 export 'decl1.dart';
812 export 'decl2.dart';
813
814 main() {}""",
815 'decl1.dart': "class Class {}",
816 'decl2.dart': "class Class {}"}]),
817
818 MessageKind.DUPLICATE_EXPORT_CONT:
819 const MessageTemplate(MessageKind.DUPLICATE_EXPORT_CONT,
820 "This is another export of '#{name}'."),
821
822 MessageKind.DUPLICATE_EXPORT_DECL:
823 const MessageTemplate(MessageKind.DUPLICATE_EXPORT_DECL,
824 "The exported '#{name}' from export #{uriString} is defined here."),
825
826 MessageKind.NOT_A_TYPE:
827 const MessageTemplate(MessageKind.NOT_A_TYPE,
828 "'#{node}' is not a type."),
829
830 MessageKind.NOT_A_PREFIX:
831 const MessageTemplate(MessageKind.NOT_A_PREFIX,
832 "'#{node}' is not a prefix."),
833
834 MessageKind.PREFIX_AS_EXPRESSION:
835 const MessageTemplate(MessageKind.PREFIX_AS_EXPRESSION,
836 "Library prefix '#{prefix}' is not a valid expression."),
837
838 MessageKind.CANNOT_FIND_CONSTRUCTOR:
839 const MessageTemplate(MessageKind.CANNOT_FIND_CONSTRUCTOR,
840 "Cannot find constructor '#{constructorName}'."),
841
842 MessageKind.CYCLIC_CLASS_HIERARCHY:
843 const MessageTemplate(MessageKind.CYCLIC_CLASS_HIERARCHY,
844 "'#{className}' creates a cycle in the class hierarchy."),
845
846 MessageKind.CYCLIC_REDIRECTING_FACTORY:
847 const MessageTemplate(MessageKind.CYCLIC_REDIRECTING_FACTORY,
848 'Redirecting factory leads to a cyclic redirection.'),
849
850 MessageKind.INVALID_RECEIVER_IN_INITIALIZER:
851 const MessageTemplate(MessageKind.INVALID_RECEIVER_IN_INITIALIZER,
852 "Field initializer expected."),
853
854 MessageKind.NO_SUPER_IN_STATIC:
855 const MessageTemplate(MessageKind.NO_SUPER_IN_STATIC,
856 "'super' is only available in instance methods."),
857
858 MessageKind.DUPLICATE_INITIALIZER:
859 const MessageTemplate(MessageKind.DUPLICATE_INITIALIZER,
860 "Field '#{fieldName}' is initialized more than once."),
861
862 MessageKind.ALREADY_INITIALIZED:
863 const MessageTemplate(MessageKind.ALREADY_INITIALIZED,
864 "'#{fieldName}' was already initialized here."),
865
866 MessageKind.INIT_STATIC_FIELD:
867 const MessageTemplate(MessageKind.INIT_STATIC_FIELD,
868 "Cannot initialize static field '#{fieldName}'."),
869
870 MessageKind.NOT_A_FIELD:
871 const MessageTemplate(MessageKind.NOT_A_FIELD,
872 "'#{fieldName}' is not a field."),
873
874 MessageKind.CONSTRUCTOR_CALL_EXPECTED:
875 const MessageTemplate(MessageKind.CONSTRUCTOR_CALL_EXPECTED,
876 "only call to 'this' or 'super' constructor allowed."),
877
878 MessageKind.INVALID_FOR_IN:
879 const MessageTemplate(MessageKind.INVALID_FOR_IN,
880 "Invalid for-in variable declaration."),
881
882 MessageKind.INVALID_INITIALIZER:
883 const MessageTemplate(MessageKind.INVALID_INITIALIZER,
884 "Invalid initializer."),
885
886 MessageKind.FUNCTION_WITH_INITIALIZER:
887 const MessageTemplate(MessageKind.FUNCTION_WITH_INITIALIZER,
888 "Only constructors can have initializers."),
889
890 MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE:
891 const MessageTemplate(MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE,
892 "Cyclic constructor redirection."),
893
894 MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY:
895 const MessageTemplate(MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY,
896 "Redirecting constructor can't have a body."),
897
898 MessageKind.CONST_CONSTRUCTOR_HAS_BODY:
899 const MessageTemplate(MessageKind.CONST_CONSTRUCTOR_HAS_BODY,
900 "Const constructor or factory can't have a body.",
901 howToFix: "Remove the 'const' keyword or the body",
902 examples: const ["""
903 class C {
904 const C() {}
905 }
906
907 main() => new C();"""]),
908
909 MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER:
910 const MessageTemplate(
911 MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER,
912 "Redirecting constructor cannot have other initializers."),
913
914 MessageKind.SUPER_INITIALIZER_IN_OBJECT:
915 const MessageTemplate(MessageKind.SUPER_INITIALIZER_IN_OBJECT,
916 "'Object' cannot have a super initializer."),
917
918 MessageKind.DUPLICATE_SUPER_INITIALIZER:
919 const MessageTemplate(MessageKind.DUPLICATE_SUPER_INITIALIZER,
920 "Cannot have more than one super initializer."),
921
922 MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS:
923 const MessageTemplate(MessageKind.INVALID_CONSTRUCTOR_ARGUMENTS,
924 "Arguments do not match the expected parameters of constructor "
925 "'#{constructorName}'."),
926
927 MessageKind.NO_MATCHING_CONSTRUCTOR:
928 const MessageTemplate(MessageKind.NO_MATCHING_CONSTRUCTOR,
929 "'super' call arguments and constructor parameters do not match."),
930
931 MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT:
932 const MessageTemplate(MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT,
933 "Implicit 'super' call arguments and constructor parameters "
934 "do not match."),
935
936 MessageKind.CONST_CALLS_NON_CONST:
937 const MessageTemplate(MessageKind.CONST_CALLS_NON_CONST,
938 "'const' constructor cannot call a non-const constructor."),
939
940 MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT:
941 const MessageTemplate(MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT,
942 "'const' constructor cannot call a non-const constructor. "
943 "This constructor has an implicit call to a "
944 "super non-const constructor.",
945 howToFix: "Try making the super constructor const.",
946 examples: const ["""
947 class C {
948 C(); // missing const
949 }
950 class D extends C {
951 final d;
952 const D(this.d);
953 }
954 main() => new D(0);"""]),
955
956 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS:
957 const MessageTemplate(
958 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS,
959 "Can't declare constructor 'const' on class #{className} "
960 "because the class contains non-final instance fields.",
961 howToFix: "Try making all fields final.",
962 examples: const ["""
963 class C {
964 // 'a' must be declared final to allow for the const constructor.
965 var a;
966 const C(this.a);
967 }
968
969 main() => new C(0);"""]),
970
971 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD:
972 const MessageTemplate(
973 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD,
974 "This non-final field prevents using const constructors."),
975
976 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR:
977 const MessageTemplate(
978 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR,
979 "This const constructor is not allowed due to "
980 "non-final fields."),
981
982
983 MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED:
984 const MessageTemplate(MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED,
985 "Initializing formal parameter only allowed in generative "
986 "constructor."),
987
988 MessageKind.INVALID_PARAMETER:
989 const MessageTemplate(MessageKind.INVALID_PARAMETER,
990 "Cannot resolve parameter."),
991
992 MessageKind.NOT_INSTANCE_FIELD:
993 const MessageTemplate(MessageKind.NOT_INSTANCE_FIELD,
994 "'#{fieldName}' is not an instance field."),
995
996 MessageKind.THIS_PROPERTY:
997 const MessageTemplate(MessageKind.THIS_PROPERTY,
998 "Expected an identifier."),
999
1000 MessageKind.NO_CATCH_NOR_FINALLY:
1001 const MessageTemplate(MessageKind.NO_CATCH_NOR_FINALLY,
1002 "Expected 'catch' or 'finally'."),
1003
1004 MessageKind.EMPTY_CATCH_DECLARATION:
1005 const MessageTemplate(MessageKind.EMPTY_CATCH_DECLARATION,
1006 "Expected an identifier in catch declaration."),
1007
1008 MessageKind.EXTRA_CATCH_DECLARATION:
1009 const MessageTemplate(MessageKind.EXTRA_CATCH_DECLARATION,
1010 "Extra parameter in catch declaration."),
1011
1012 MessageKind.PARAMETER_WITH_TYPE_IN_CATCH:
1013 const MessageTemplate(MessageKind.PARAMETER_WITH_TYPE_IN_CATCH,
1014 "Cannot use type annotations in catch."),
1015
1016 MessageKind.PARAMETER_WITH_MODIFIER_IN_CATCH:
1017 const MessageTemplate(MessageKind.PARAMETER_WITH_MODIFIER_IN_CATCH,
1018 "Cannot use modifiers in catch."),
1019
1020 MessageKind.OPTIONAL_PARAMETER_IN_CATCH:
1021 const MessageTemplate(MessageKind.OPTIONAL_PARAMETER_IN_CATCH,
1022 "Cannot use optional parameters in catch."),
1023
1024 MessageKind.THROW_WITHOUT_EXPRESSION:
1025 const MessageTemplate(MessageKind.THROW_WITHOUT_EXPRESSION,
1026 "Cannot use re-throw outside of catch block "
1027 "(expression expected after 'throw')."),
1028
1029 MessageKind.UNBOUND_LABEL:
1030 const MessageTemplate(MessageKind.UNBOUND_LABEL,
1031 "Cannot resolve label '#{labelName}'."),
1032
1033 MessageKind.NO_BREAK_TARGET:
1034 const MessageTemplate(MessageKind.NO_BREAK_TARGET,
1035 "'break' statement not inside switch or loop."),
1036
1037 MessageKind.NO_CONTINUE_TARGET:
1038 const MessageTemplate(MessageKind.NO_CONTINUE_TARGET,
1039 "'continue' statement not inside loop."),
1040
1041 MessageKind.EXISTING_LABEL:
1042 const MessageTemplate(MessageKind.EXISTING_LABEL,
1043 "Original declaration of duplicate label '#{labelName}'."),
1044
1045 MessageKind.DUPLICATE_LABEL:
1046 const MessageTemplate(MessageKind.DUPLICATE_LABEL,
1047 "Duplicate declaration of label '#{labelName}'."),
1048
1049 MessageKind.UNUSED_LABEL:
1050 const MessageTemplate(MessageKind.UNUSED_LABEL,
1051 "Unused label '#{labelName}'."),
1052
1053 MessageKind.INVALID_CONTINUE:
1054 const MessageTemplate(MessageKind.INVALID_CONTINUE,
1055 "Target of continue is not a loop or switch case."),
1056
1057 MessageKind.INVALID_BREAK:
1058 const MessageTemplate(MessageKind.INVALID_BREAK,
1059 "Target of break is not a statement."),
1060
1061 MessageKind.DUPLICATE_TYPE_VARIABLE_NAME:
1062 const MessageTemplate(MessageKind.DUPLICATE_TYPE_VARIABLE_NAME,
1063 "Type variable '#{typeVariableName}' already declared."),
1064
1065 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER:
1066 const MessageTemplate(MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1067 "Cannot refer to type variable '#{typeVariableName}' "
1068 "within a static member."),
1069
1070 MessageKind.TYPE_VARIABLE_IN_CONSTANT:
1071 const MessageTemplate(MessageKind.TYPE_VARIABLE_IN_CONSTANT,
1072 "Constant expressions can't refer to type variables.",
1073 howToFix: "Try removing the type variable or replacing it with a "
1074 "concrete type.",
1075 examples: const ["""
1076 class C<T> {
1077 const C();
1078
1079 m(T t) => const C<T>();
1080 }
1081
1082 void main() => new C().m(null);
1083 """
1084 ]),
1085
1086 MessageKind.INVALID_TYPE_VARIABLE_BOUND:
1087 const MessageTemplate(MessageKind.INVALID_TYPE_VARIABLE_BOUND,
1088 "'#{typeArgument}' is not a subtype of bound '#{bound}' for "
1089 "type variable '#{typeVariable}' of type '#{thisType}'.",
1090 howToFix: "Try to change or remove the type argument.",
1091 examples: const ["""
1092 class C<T extends num> {}
1093
1094 // 'String' is not a valid instantiation of T with bound num.'.
1095 main() => new C<String>();
1096 """]),
1097
1098 MessageKind.INVALID_USE_OF_SUPER:
1099 const MessageTemplate(MessageKind.INVALID_USE_OF_SUPER,
1100 "'super' not allowed here."),
1101
1102 MessageKind.INVALID_CASE_DEFAULT:
1103 const MessageTemplate(MessageKind.INVALID_CASE_DEFAULT,
1104 "'default' only allowed on last case of a switch."),
1105
1106 MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL:
1107 const MessageTemplate(MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL,
1108 "'case' expressions do not all have type '#{type}'."),
1109
1110 MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE:
1111 const MessageTemplate(MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE,
1112 "'case' expression of type '#{type}'."),
1113
1114 MessageKind.SWITCH_CASE_FORBIDDEN:
1115 const MessageTemplate(MessageKind.SWITCH_CASE_FORBIDDEN,
1116 "'case' expression may not be of type '#{type}'."),
1117
1118 MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS:
1119 const MessageTemplate(MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS,
1120 "'case' expression type '#{type}' overrides 'operator =='."),
1121
1122 MessageKind.INVALID_ARGUMENT_AFTER_NAMED:
1123 const MessageTemplate(MessageKind.INVALID_ARGUMENT_AFTER_NAMED,
1124 "Unnamed argument after named argument."),
1125
1126 MessageKind.NOT_A_COMPILE_TIME_CONSTANT:
1127 const MessageTemplate(MessageKind.NOT_A_COMPILE_TIME_CONSTANT,
1128 "Not a compile-time constant."),
1129
1130 MessageKind.DEFERRED_COMPILE_TIME_CONSTANT:
1131 const MessageTemplate(MessageKind.DEFERRED_COMPILE_TIME_CONSTANT,
1132 "A deferred value cannot be used as a compile-time constant."),
1133
1134 MessageKind.DEFERRED_COMPILE_TIME_CONSTANT_CONSTRUCTION:
1135 const MessageTemplate(
1136 MessageKind.DEFERRED_COMPILE_TIME_CONSTANT_CONSTRUCTION,
1137 "A deferred class cannot be used to create a "
1138 "compile-time constant."),
1139
1140 MessageKind.CYCLIC_COMPILE_TIME_CONSTANTS:
1141 const MessageTemplate(MessageKind.CYCLIC_COMPILE_TIME_CONSTANTS,
1142 "Cycle in the compile-time constant computation."),
1143
1144 MessageKind.CONSTRUCTOR_IS_NOT_CONST:
1145 const MessageTemplate(MessageKind.CONSTRUCTOR_IS_NOT_CONST,
1146 "Constructor is not a 'const' constructor."),
1147
1148 MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS:
1149 const MessageTemplate(MessageKind.CONST_MAP_KEY_OVERRIDES_EQUALS,
1150 "Const-map key type '#{type}' overrides 'operator =='."),
1151
1152 MessageKind.NO_SUCH_LIBRARY_MEMBER:
1153 const MessageTemplate(MessageKind.NO_SUCH_LIBRARY_MEMBER,
1154 "'#{libraryName}' has no member named '#{memberName}'."),
1155
1156 MessageKind.CANNOT_INSTANTIATE_TYPEDEF:
1157 const MessageTemplate(MessageKind.CANNOT_INSTANTIATE_TYPEDEF,
1158 "Cannot instantiate typedef '#{typedefName}'."),
1159
1160 MessageKind.REQUIRED_PARAMETER_WITH_DEFAULT:
1161 const MessageTemplate(MessageKind.REQUIRED_PARAMETER_WITH_DEFAULT,
1162 "Non-optional parameters can't have a default value.",
1163 howToFix:
1164 "Try removing the default value or making the parameter optional.",
1165 examples: const ["""
1166 main() {
1167 foo(a: 1) => print(a);
1168 foo(2);
1169 }""", """
1170 main() {
1171 foo(a = 1) => print(a);
1172 foo(2);
1173 }"""]),
1174
1175 MessageKind.NAMED_PARAMETER_WITH_EQUALS:
1176 const MessageTemplate(MessageKind.NAMED_PARAMETER_WITH_EQUALS,
1177 "Named optional parameters can't use '=' to specify a default "
1178 "value.",
1179 howToFix: "Try replacing '=' with ':'.",
1180 examples: const ["""
1181 main() {
1182 foo({a = 1}) => print(a);
1183 foo(a: 2);
1184 }"""]),
1185
1186 MessageKind.POSITIONAL_PARAMETER_WITH_EQUALS:
1187 const MessageTemplate(MessageKind.POSITIONAL_PARAMETER_WITH_EQUALS,
1188 "Positional optional parameters can't use ':' to specify a "
1189 "default value.",
1190 howToFix: "Try replacing ':' with '='.",
1191 examples: const ["""
1192 main() {
1193 foo([a: 1]) => print(a);
1194 foo(2);
1195 }"""]),
1196
1197 MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT:
1198 const MessageTemplate(MessageKind.TYPEDEF_FORMAL_WITH_DEFAULT,
1199 "A parameter of a typedef can't specify a default value.",
1200 howToFix:
1201 "Try removing the default value.",
1202 examples: const ["""
1203 typedef void F([int arg = 0]);
1204
1205 main() {
1206 F f;
1207 }""", """
1208 typedef void F({int arg: 0});
1209
1210 main() {
1211 F f;
1212 }"""]),
1213
1214 MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT:
1215 const MessageTemplate(MessageKind.FUNCTION_TYPE_FORMAL_WITH_DEFAULT,
1216 "A function type parameter can't specify a default value.",
1217 howToFix:
1218 "Try removing the default value.",
1219 examples: const ["""
1220 foo(f(int i, [a = 1])) {}
1221
1222 main() {
1223 foo(1, 2);
1224 }""", """
1225 foo(f(int i, {a: 1})) {}
1226
1227 main() {
1228 foo(1, a: 2);
1229 }"""]),
1230
1231 MessageKind.REDIRECTING_FACTORY_WITH_DEFAULT:
1232 const MessageTemplate(MessageKind.REDIRECTING_FACTORY_WITH_DEFAULT,
1233 "A parameter of a redirecting factory constructor can't specify a "
1234 "default value.",
1235 howToFix:
1236 "Try removing the default value.",
1237 examples: const ["""
1238 class A {
1239 A([a]);
1240 factory A.foo([a = 1]) = A;
1241 }
1242
1243 main() {
1244 new A.foo(1);
1245 }""", """
1246 class A {
1247 A({a});
1248 factory A.foo({a: 1}) = A;
1249 }
1250
1251 main() {
1252 new A.foo(a: 1);
1253 }"""]),
1254
1255 MessageKind.FORMAL_DECLARED_CONST:
1256 const MessageTemplate(MessageKind.FORMAL_DECLARED_CONST,
1257 "A formal parameter can't be declared const.",
1258 howToFix: "Try removing 'const'.",
1259 examples: const ["""
1260 foo(const x) {}
1261 main() => foo(42);
1262 """, """
1263 foo({const x}) {}
1264 main() => foo(42);
1265 """, """
1266 foo([const x]) {}
1267 main() => foo(42);
1268 """]),
1269
1270 MessageKind.FORMAL_DECLARED_STATIC:
1271 const MessageTemplate(MessageKind.FORMAL_DECLARED_STATIC,
1272 "A formal parameter can't be declared static.",
1273 howToFix: "Try removing 'static'.",
1274 examples: const ["""
1275 foo(static x) {}
1276 main() => foo(42);
1277 """, """
1278 foo({static x}) {}
1279 main() => foo(42);
1280 """, """
1281 foo([static x]) {}
1282 main() => foo(42);
1283 """]),
1284
1285 MessageKind.FINAL_FUNCTION_TYPE_PARAMETER:
1286 const MessageTemplate(MessageKind.FINAL_FUNCTION_TYPE_PARAMETER,
1287 "A function type parameter can't be declared final.",
1288 howToFix: "Try removing 'final'.",
1289 examples: const ["""
1290 foo(final int x(int a)) {}
1291 main() => foo((y) => 42);
1292 """, """
1293 foo({final int x(int a)}) {}
1294 main() => foo((y) => 42);
1295 """, """
1296 foo([final int x(int a)]) {}
1297 main() => foo((y) => 42);
1298 """]),
1299
1300 MessageKind.VAR_FUNCTION_TYPE_PARAMETER:
1301 const MessageTemplate(MessageKind.VAR_FUNCTION_TYPE_PARAMETER,
1302 "A function type parameter can't be declared with 'var'.",
1303 howToFix: "Try removing 'var'.",
1304 examples: const ["""
1305 foo(var int x(int a)) {}
1306 main() => foo((y) => 42);
1307 """, """
1308 foo({var int x(int a)}) {}
1309 main() => foo((y) => 42);
1310 """, """
1311 foo([var int x(int a)]) {}
1312 main() => foo((y) => 42);
1313 """]),
1314
1315 MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE:
1316 const MessageTemplate(MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE,
1317 "Cannot instantiate type variable '#{typeVariableName}'."),
1318
1319 MessageKind.CYCLIC_TYPE_VARIABLE:
1320 const MessageTemplate(MessageKind.CYCLIC_TYPE_VARIABLE,
1321 "Type variable '#{typeVariableName}' is a supertype of itself."),
1322
1323 MessageKind.CYCLIC_TYPEDEF:
1324 const MessageTemplate(MessageKind.CYCLIC_TYPEDEF,
1325 "A typedef can't refer to itself.",
1326 howToFix: "Try removing all references to '#{typedefName}' "
1327 "in the definition of '#{typedefName}'.",
1328 examples: const ["""
1329 typedef F F(); // The return type 'F' is a self-reference.
1330 main() { F f = null; }"""]),
1331
1332 MessageKind.CYCLIC_TYPEDEF_ONE:
1333 const MessageTemplate(MessageKind.CYCLIC_TYPEDEF_ONE,
1334 "A typedef can't refer to itself through another typedef.",
1335 howToFix:
1336 "Try removing all references to "
1337 "'#{otherTypedefName}' in the definition of '#{typedefName}'.",
1338 examples: const ["""
1339 typedef G F(); // The return type 'G' is a self-reference through typedef 'G'.
1340 typedef F G(); // The return type 'F' is a self-reference through typedef 'F'.
1341 main() { F f = null; }""",
1342 """
1343 typedef G F(); // The return type 'G' creates a self-reference.
1344 typedef H G(); // The return type 'H' creates a self-reference.
1345 typedef H(F f); // The argument type 'F' creates a self-reference.
1346 main() { F f = null; }"""]),
1347
1348 MessageKind.CLASS_NAME_EXPECTED:
1349 const MessageTemplate(MessageKind.CLASS_NAME_EXPECTED,
1350 "Class name expected."),
1351
1352 MessageKind.CANNOT_EXTEND:
1353 const MessageTemplate(MessageKind.CANNOT_EXTEND,
1354 "'#{type}' cannot be extended."),
1355
1356 MessageKind.CANNOT_IMPLEMENT:
1357 const MessageTemplate(MessageKind.CANNOT_IMPLEMENT,
1358 "'#{type}' cannot be implemented."),
1359
1360 // TODO(johnnwinther): Split messages into reasons for malformedness.
1361 MessageKind.CANNOT_EXTEND_MALFORMED:
1362 const MessageTemplate(MessageKind.CANNOT_EXTEND_MALFORMED,
1363 "Class '#{className}' can't extend the type '#{malformedType}' "
1364 "because it is malformed.",
1365 howToFix:
1366 "Try correcting the malformed type annotation or removing the "
1367 "'extends' clause.",
1368 examples: const ["""
1369 class A extends Malformed {}
1370 main() => new A();"""]),
1371
1372 MessageKind.CANNOT_IMPLEMENT_MALFORMED:
1373 const MessageTemplate(MessageKind.CANNOT_IMPLEMENT_MALFORMED,
1374 "Class '#{className}' can't implement the type '#{malformedType}' "
1375 "because it is malformed.",
1376 howToFix:
1377 "Try correcting the malformed type annotation or removing the "
1378 "type from the 'implements' clause.",
1379 examples: const ["""
1380 class A implements Malformed {}
1381 main() => new A();"""]),
1382
1383 MessageKind.CANNOT_MIXIN_MALFORMED:
1384 const MessageTemplate(MessageKind.CANNOT_MIXIN_MALFORMED,
1385 "Class '#{className}' can't mixin the type '#{malformedType}' "
1386 "because it is malformed.",
1387 howToFix:
1388 "Try correcting the malformed type annotation or removing the "
1389 "type from the 'with' clause.",
1390 examples: const ["""
1391 class A extends Object with Malformed {}
1392 main() => new A();"""]),
1393
1394 MessageKind.CANNOT_MIXIN:
1395 const MessageTemplate(MessageKind.CANNOT_MIXIN,
1396 "The type '#{type}' can't be mixed in.",
1397 howToFix: "Try removing '#{type}' from the 'with' clause.",
1398 examples: const ["""
1399 class C extends Object with String {}
1400
1401 main() => new C();
1402 """, """
1403 typedef C = Object with String;
1404
1405 main() => new C();
1406 """]),
1407
1408 MessageKind.CANNOT_EXTEND_ENUM:
1409 const MessageTemplate(MessageKind.CANNOT_EXTEND_ENUM,
1410 "Class '#{className}' can't extend the type '#{enumType}' because "
1411 "it is declared by an enum.",
1412 howToFix: "Try making '#{enumType}' a normal class or removing the "
1413 "'extends' clause.",
1414 examples: const ["""
1415 enum Enum { A }
1416 class B extends Enum {}
1417 main() => new B();"""]),
1418
1419 MessageKind.CANNOT_IMPLEMENT_ENUM:
1420 const MessageTemplate(MessageKind.CANNOT_IMPLEMENT_ENUM,
1421 "Class '#{className}' can't implement the type '#{enumType}' "
1422 "because it is declared by an enum.",
1423 howToFix: "Try making '#{enumType}' a normal class or removing the "
1424 "type from the 'implements' clause.",
1425 examples: const ["""
1426 enum Enum { A }
1427 class B implements Enum {}
1428 main() => new B();"""]),
1429
1430 MessageKind.CANNOT_MIXIN_ENUM:
1431 const MessageTemplate(MessageKind.CANNOT_MIXIN_ENUM,
1432 "Class '#{className}' can't mixin the type '#{enumType}' because it "
1433 "is declared by an enum.",
1434 howToFix: "Try making '#{enumType}' a normal class or removing the "
1435 "type from the 'with' clause.",
1436 examples: const ["""
1437 enum Enum { A }
1438 class B extends Object with Enum {}
1439 main() => new B();"""]),
1440
1441 MessageKind.CANNOT_INSTANTIATE_ENUM:
1442 const MessageTemplate(MessageKind.CANNOT_INSTANTIATE_ENUM,
1443 "Enum type '#{enumName}' cannot be instantiated.",
1444 howToFix: "Try making '#{enumType}' a normal class or use an enum "
1445 "constant.",
1446 examples: const ["""
1447 enum Enum { A }
1448 main() => new Enum(0);""", """
1449 enum Enum { A }
1450 main() => const Enum(0);"""]),
1451
1452 MessageKind.EMPTY_ENUM_DECLARATION:
1453 const MessageTemplate(MessageKind.EMPTY_ENUM_DECLARATION,
1454 "Enum '#{enumName}' must contain at least one value.",
1455 howToFix: "Try adding an enum constant or making #{enumName} a "
1456 "normal class.",
1457 examples: const ["""
1458 enum Enum {}
1459 main() { Enum e; }"""]),
1460
1461 MessageKind.MISSING_ENUM_CASES:
1462 const MessageTemplate(MessageKind.MISSING_ENUM_CASES,
1463 "Missing enum constants in switch statement: #{enumValues}.",
1464 howToFix: "Try adding the missing constants or a default case.",
1465 examples: const ["""
1466 enum Enum { A, B }
1467 main() {
1468 switch (Enum.A) {
1469 case Enum.B: break;
1470 }
1471 }""", """
1472 enum Enum { A, B, C }
1473 main() {
1474 switch (Enum.A) {
1475 case Enum.B: break;
1476 }
1477 }"""]),
1478
1479 MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS:
1480 const MessageTemplate(MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS,
1481 "'#{type}' can not be both extended and implemented."),
1482
1483 MessageKind.DUPLICATE_IMPLEMENTS:
1484 const MessageTemplate(MessageKind.DUPLICATE_IMPLEMENTS,
1485 "'#{type}' must not occur more than once "
1486 "in the implements clause."),
1487
1488 MessageKind.MULTI_INHERITANCE:
1489 const MessageTemplate(MessageKind.MULTI_INHERITANCE,
1490 "Dart2js does not currently support inheritance of the same class "
1491 "with different type arguments: Both #{firstType} and #{secondType} "
1492 "are supertypes of #{thisType}."),
1493
1494 MessageKind.ILLEGAL_SUPER_SEND:
1495 const MessageTemplate(MessageKind.ILLEGAL_SUPER_SEND,
1496 "'#{name}' cannot be called on super."),
1497
1498 MessageKind.NO_SUCH_SUPER_MEMBER:
1499 const MessageTemplate(MessageKind.NO_SUCH_SUPER_MEMBER,
1500 "Cannot resolve '#{memberName}' in a superclass of '#{className}'."),
1501
1502 MessageKind.ADDITIONAL_TYPE_ARGUMENT:
1503 const MessageTemplate(MessageKind.ADDITIONAL_TYPE_ARGUMENT,
1504 "Additional type argument."),
1505
1506 MessageKind.MISSING_TYPE_ARGUMENT:
1507 const MessageTemplate(MessageKind.MISSING_TYPE_ARGUMENT,
1508 "Missing type argument."),
1509
1510 // TODO(johnniwinther): Use ADDITIONAL_TYPE_ARGUMENT or
1511 // MISSING_TYPE_ARGUMENT instead.
1512 MessageKind.TYPE_ARGUMENT_COUNT_MISMATCH:
1513 const MessageTemplate(MessageKind.TYPE_ARGUMENT_COUNT_MISMATCH,
1514 "Incorrect number of type arguments on '#{type}'."),
1515
1516 MessageKind.GETTER_MISMATCH:
1517 const MessageTemplate(MessageKind.GETTER_MISMATCH,
1518 "Setter disagrees on: '#{modifiers}'."),
1519
1520 MessageKind.SETTER_MISMATCH:
1521 const MessageTemplate(MessageKind.SETTER_MISMATCH,
1522 "Getter disagrees on: '#{modifiers}'."),
1523
1524 MessageKind.ILLEGAL_SETTER_FORMALS:
1525 const MessageTemplate(MessageKind.ILLEGAL_SETTER_FORMALS,
1526 "A setter must have exactly one argument."),
1527
1528 MessageKind.NO_STATIC_OVERRIDE:
1529 const MessageTemplate(MessageKind.NO_STATIC_OVERRIDE,
1530 "Static member cannot override instance member '#{memberName}' of "
1531 "'#{className}'."),
1532
1533 MessageKind.NO_STATIC_OVERRIDE_CONT:
1534 const MessageTemplate(MessageKind.NO_STATIC_OVERRIDE_CONT,
1535 "This is the instance member that cannot be overridden "
1536 "by a static member."),
1537
1538 MessageKind.INSTANCE_STATIC_SAME_NAME:
1539 const MessageTemplate(MessageKind.INSTANCE_STATIC_SAME_NAME,
1540 "Instance member '#{memberName}' and static member of "
1541 "superclass '#{className}' have the same name."),
1542
1543 MessageKind.INSTANCE_STATIC_SAME_NAME_CONT:
1544 const MessageTemplate(MessageKind.INSTANCE_STATIC_SAME_NAME_CONT,
1545 "This is the static member with the same name."),
1546
1547 MessageKind.INVALID_OVERRIDE_METHOD:
1548 const MessageTemplate(MessageKind.INVALID_OVERRIDE_METHOD,
1549 "The type '#{declaredType}' of method '#{name}' declared in "
1550 "'#{class}' is not a subtype of the overridden method type "
1551 "'#{inheritedType}' inherited from '#{inheritedClass}'."),
1552
1553 MessageKind.INVALID_OVERRIDDEN_METHOD:
1554 const MessageTemplate(MessageKind.INVALID_OVERRIDDEN_METHOD,
1555 "This is the overridden method '#{name}' declared in class "
1556 "'#{class}'."),
1557
1558 MessageKind.INVALID_OVERRIDE_GETTER:
1559 const MessageTemplate(MessageKind.INVALID_OVERRIDE_GETTER,
1560 "The type '#{declaredType}' of getter '#{name}' declared in "
1561 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
1562 "overridden getter inherited from '#{inheritedClass}'."),
1563
1564 MessageKind.INVALID_OVERRIDDEN_GETTER:
1565 const MessageTemplate(MessageKind.INVALID_OVERRIDDEN_GETTER,
1566 "This is the overridden getter '#{name}' declared in class "
1567 "'#{class}'."),
1568
1569 MessageKind.INVALID_OVERRIDE_GETTER_WITH_FIELD:
1570 const MessageTemplate(MessageKind.INVALID_OVERRIDE_GETTER_WITH_FIELD,
1571 "The type '#{declaredType}' of field '#{name}' declared in "
1572 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
1573 "overridden getter inherited from '#{inheritedClass}'."),
1574
1575 MessageKind.INVALID_OVERRIDE_FIELD_WITH_GETTER:
1576 const MessageTemplate(MessageKind.INVALID_OVERRIDE_FIELD_WITH_GETTER,
1577 "The type '#{declaredType}' of getter '#{name}' declared in "
1578 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
1579 "overridden field inherited from '#{inheritedClass}'."),
1580
1581 MessageKind.INVALID_OVERRIDE_SETTER:
1582 const MessageTemplate(MessageKind.INVALID_OVERRIDE_SETTER,
1583 "The type '#{declaredType}' of setter '#{name}' declared in "
1584 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
1585 "overridden setter inherited from '#{inheritedClass}'."),
1586
1587 MessageKind.INVALID_OVERRIDDEN_SETTER:
1588 const MessageTemplate(MessageKind.INVALID_OVERRIDDEN_SETTER,
1589 "This is the overridden setter '#{name}' declared in class "
1590 "'#{class}'."),
1591
1592 MessageKind.INVALID_OVERRIDE_SETTER_WITH_FIELD:
1593 const MessageTemplate(MessageKind.INVALID_OVERRIDE_SETTER_WITH_FIELD,
1594 "The type '#{declaredType}' of field '#{name}' declared in "
1595 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
1596 "overridden setter inherited from '#{inheritedClass}'."),
1597
1598 MessageKind.INVALID_OVERRIDE_FIELD_WITH_SETTER:
1599 const MessageTemplate(MessageKind.INVALID_OVERRIDE_FIELD_WITH_SETTER,
1600 "The type '#{declaredType}' of setter '#{name}' declared in "
1601 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
1602 "overridden field inherited from '#{inheritedClass}'."),
1603
1604 MessageKind.INVALID_OVERRIDE_FIELD:
1605 const MessageTemplate(MessageKind.INVALID_OVERRIDE_FIELD,
1606 "The type '#{declaredType}' of field '#{name}' declared in "
1607 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
1608 "overridden field inherited from '#{inheritedClass}'."),
1609
1610 MessageKind.INVALID_OVERRIDDEN_FIELD:
1611 const MessageTemplate(MessageKind.INVALID_OVERRIDDEN_FIELD,
1612 "This is the overridden field '#{name}' declared in class "
1613 "'#{class}'."),
1614
1615 MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD:
1616 const MessageTemplate(MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD,
1617 "Method '#{name}' in '#{class}' can't override field from "
1618 "'#{inheritedClass}'."),
1619
1620 MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT:
1621 const MessageTemplate(
1622 MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT,
1623 "This is the field that cannot be overridden by a method."),
1624
1625 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD:
1626 const MessageTemplate(
1627 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD,
1628 "Field '#{name}' in '#{class}' can't override method from "
1629 "'#{inheritedClass}'."),
1630
1631 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT:
1632 const MessageTemplate(
1633 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT,
1634 "This is the method that cannot be overridden by a field."),
1635
1636 MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD:
1637 const MessageTemplate(MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD,
1638 "Method '#{name}' in '#{class}' can't override getter from "
1639 "'#{inheritedClass}'."),
1640
1641 MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD_CONT:
1642 const MessageTemplate(
1643 MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD_CONT,
1644 "This is the getter that cannot be overridden by a method."),
1645
1646 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER:
1647 const MessageTemplate(MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER,
1648 "Getter '#{name}' in '#{class}' can't override method from "
1649 "'#{inheritedClass}'."),
1650
1651 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT:
1652 const MessageTemplate(
1653 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT,
1654 "This is the method that cannot be overridden by a getter."),
1655
1656 MessageKind.MISSING_FORMALS:
1657 const MessageTemplate(MessageKind.MISSING_FORMALS,
1658 "Formal parameters are missing."),
1659
1660 MessageKind.EXTRA_FORMALS:
1661 const MessageTemplate(MessageKind.EXTRA_FORMALS,
1662 "Formal parameters are not allowed here."),
1663
1664 MessageKind.UNARY_OPERATOR_BAD_ARITY:
1665 const MessageTemplate(MessageKind.UNARY_OPERATOR_BAD_ARITY,
1666 "Operator '#{operatorName}' must have no parameters."),
1667
1668 MessageKind.MINUS_OPERATOR_BAD_ARITY:
1669 const MessageTemplate(MessageKind.MINUS_OPERATOR_BAD_ARITY,
1670 "Operator '-' must have 0 or 1 parameters."),
1671
1672 MessageKind.BINARY_OPERATOR_BAD_ARITY:
1673 const MessageTemplate(MessageKind.BINARY_OPERATOR_BAD_ARITY,
1674 "Operator '#{operatorName}' must have exactly 1 parameter."),
1675
1676 MessageKind.TERNARY_OPERATOR_BAD_ARITY:
1677 const MessageTemplate(MessageKind.TERNARY_OPERATOR_BAD_ARITY,
1678 "Operator '#{operatorName}' must have exactly 2 parameters."),
1679
1680 MessageKind.OPERATOR_OPTIONAL_PARAMETERS:
1681 const MessageTemplate(MessageKind.OPERATOR_OPTIONAL_PARAMETERS,
1682 "Operator '#{operatorName}' cannot have optional parameters."),
1683
1684 MessageKind.OPERATOR_NAMED_PARAMETERS:
1685 const MessageTemplate(MessageKind.OPERATOR_NAMED_PARAMETERS,
1686 "Operator '#{operatorName}' cannot have named parameters."),
1687
1688 MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE:
1689 const MessageTemplate(MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE,
1690 "Cannot have return type for constructor."),
1691
1692 MessageKind.CANNOT_RETURN_FROM_CONSTRUCTOR:
1693 const MessageTemplate(MessageKind.CANNOT_RETURN_FROM_CONSTRUCTOR,
1694 "Constructors can't return values.",
1695 howToFix: "Remove the return statement or use a factory constructor.",
1696 examples: const ["""
1697 class C {
1698 C() {
1699 return 1;
1700 }
1701 }
1702
1703 main() => new C();"""]),
1704
1705 MessageKind.ILLEGAL_FINAL_METHOD_MODIFIER:
1706 const MessageTemplate(MessageKind.ILLEGAL_FINAL_METHOD_MODIFIER,
1707 "Cannot have final modifier on method."),
1708
1709 MessageKind.ILLEGAL_CONST_FIELD_MODIFIER:
1710 const MessageTemplate(MessageKind.ILLEGAL_CONST_FIELD_MODIFIER,
1711 "Cannot have const modifier on non-static field.",
1712 howToFix:
1713 "Try adding a static modifier, or removing the const modifier.",
1714 examples: const ["""
1715 class C {
1716 const int a = 1;
1717 }
1718
1719 main() => new C();"""]),
1720
1721 MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS:
1722 const MessageTemplate(MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS,
1723 "Illegal constructor modifiers: '#{modifiers}'."),
1724
1725 MessageKind.ILLEGAL_MIXIN_APPLICATION_MODIFIERS:
1726 const MessageTemplate(MessageKind.ILLEGAL_MIXIN_APPLICATION_MODIFIERS,
1727 "Illegal mixin application modifiers: '#{modifiers}'."),
1728
1729 MessageKind.ILLEGAL_MIXIN_SUPERCLASS:
1730 const MessageTemplate(MessageKind.ILLEGAL_MIXIN_SUPERCLASS,
1731 "Class used as mixin must have Object as superclass."),
1732
1733 MessageKind.ILLEGAL_MIXIN_OBJECT:
1734 const MessageTemplate(MessageKind.ILLEGAL_MIXIN_OBJECT,
1735 "Cannot use Object as mixin."),
1736
1737 MessageKind.ILLEGAL_MIXIN_CONSTRUCTOR:
1738 const MessageTemplate(MessageKind.ILLEGAL_MIXIN_CONSTRUCTOR,
1739 "Class used as mixin cannot have non-factory constructor."),
1740
1741 MessageKind.ILLEGAL_MIXIN_CYCLE:
1742 const MessageTemplate(MessageKind.ILLEGAL_MIXIN_CYCLE,
1743 "Class used as mixin introduces mixin cycle: "
1744 "'#{mixinName1}' <-> '#{mixinName2}'."),
1745
1746 MessageKind.ILLEGAL_MIXIN_WITH_SUPER:
1747 const MessageTemplate(MessageKind.ILLEGAL_MIXIN_WITH_SUPER,
1748 "Cannot use class '#{className}' as a mixin because it uses "
1749 "'super'."),
1750
1751 MessageKind.ILLEGAL_MIXIN_SUPER_USE:
1752 const MessageTemplate(MessageKind.ILLEGAL_MIXIN_SUPER_USE,
1753 "Use of 'super' in class used as mixin."),
1754
1755 MessageKind.PARAMETER_NAME_EXPECTED:
1756 const MessageTemplate(MessageKind.PARAMETER_NAME_EXPECTED,
1757 "parameter name expected."),
1758
1759 MessageKind.CANNOT_RESOLVE_GETTER:
1760 const MessageTemplate(MessageKind.CANNOT_RESOLVE_GETTER,
1761 "Cannot resolve getter."),
1762
1763 MessageKind.CANNOT_RESOLVE_SETTER:
1764 const MessageTemplate(MessageKind.CANNOT_RESOLVE_SETTER,
1765 "Cannot resolve setter."),
1766
1767 MessageKind.ASSIGNING_FINAL_FIELD_IN_SUPER:
1768 const MessageTemplate(MessageKind.ASSIGNING_FINAL_FIELD_IN_SUPER,
1769 "Cannot assign a value to final field '#{name}' "
1770 "in superclass '#{superclassName}'."),
1771
1772 MessageKind.ASSIGNING_METHOD:
1773 const MessageTemplate(MessageKind.ASSIGNING_METHOD,
1774 "Cannot assign a value to a method."),
1775
1776 MessageKind.ASSIGNING_METHOD_IN_SUPER:
1777 const MessageTemplate(MessageKind.ASSIGNING_METHOD_IN_SUPER,
1778 "Cannot assign a value to method '#{name}' "
1779 "in superclass '#{superclassName}'."),
1780
1781 MessageKind.ASSIGNING_TYPE:
1782 const MessageTemplate(MessageKind.ASSIGNING_TYPE,
1783 "Cannot assign a value to a type."),
1784
1785 MessageKind.IF_NULL_ASSIGNING_TYPE:
1786 const MessageTemplate(MessageKind.IF_NULL_ASSIGNING_TYPE,
1787 "Cannot assign a value to a type. Note that types are never null, "
1788 "so this ??= assignment has no effect.",
1789 howToFix: "Try removing the '??=' assignment.",
1790 examples: const [
1791 "class A {} main() { print(A ??= 3);}",
1792 ]),
1793
1794 MessageKind.VOID_NOT_ALLOWED:
1795 const MessageTemplate(MessageKind.VOID_NOT_ALLOWED,
1796 "Type 'void' can't be used here because it isn't a return type.",
1797 howToFix:
1798 "Try removing 'void' keyword or replace it with 'var', 'final', "
1799 "or a type.",
1800 examples: const [
1801 "void x; main() {}",
1802 "foo(void x) {} main() { foo(null); }",
1803 ]),
1804
1805 MessageKind.NULL_NOT_ALLOWED:
1806 const MessageTemplate(MessageKind.NULL_NOT_ALLOWED,
1807 "`null` can't be used here."),
1808
1809 MessageKind.BEFORE_TOP_LEVEL:
1810 const MessageTemplate(MessageKind.BEFORE_TOP_LEVEL,
1811 "Part header must come before top-level definitions."),
1812
1813 MessageKind.IMPORT_PART_OF:
1814 const MessageTemplate(MessageKind.IMPORT_PART_OF,
1815 "The imported library must not have a 'part-of' directive.",
1816 howToFix: "Try removing the 'part-of' directive or replacing the "
1817 "import of the library with a 'part' directive.",
1818 examples: const [const {
1819 'main.dart': """
1820 library library;
1821
1822 import 'part.dart';
1823
1824 main() {}
1825 """,
1826
1827 'part.dart': """
1828 part of library;
1829 """}]),
1830
1831 MessageKind.LIBRARY_NAME_MISMATCH:
1832 const MessageTemplate(MessageKind.LIBRARY_NAME_MISMATCH,
1833 "Expected part of library name '#{libraryName}'.",
1834 howToFix: "Try changing the directive to 'part of #{libraryName};'.",
1835 examples: const [const {
1836 'main.dart': """
1837 library lib.foo;
1838
1839 part 'part.dart';
1840
1841 main() {}
1842 """,
1843
1844 'part.dart': """
1845 part of lib.bar;
1846 """}]),
1847
1848 MessageKind.MISSING_LIBRARY_NAME:
1849 const MessageTemplate(MessageKind.MISSING_LIBRARY_NAME,
1850 "Library has no name. Part directive expected library name "
1851 "to be '#{libraryName}'.",
1852 howToFix: "Try adding 'library #{libraryName};' to the library.",
1853 examples: const [const {
1854 'main.dart': """
1855 part 'part.dart';
1856
1857 main() {}
1858 """,
1859
1860 'part.dart': """
1861 part of lib.foo;
1862 """}]),
1863
1864 MessageKind.THIS_IS_THE_PART_OF_TAG:
1865 const MessageTemplate(MessageKind.THIS_IS_THE_PART_OF_TAG,
1866 "This is the part of directive."),
1867
1868 MessageKind.MISSING_PART_OF_TAG:
1869 const MessageTemplate(MessageKind.MISSING_PART_OF_TAG,
1870 "This file has no part-of tag, but it is being used as a part."),
1871
1872 MessageKind.DUPLICATED_PART_OF:
1873 const MessageTemplate(MessageKind.DUPLICATED_PART_OF,
1874 "Duplicated part-of directive."),
1875
1876 MessageKind.DUPLICATED_LIBRARY_NAME:
1877 const MessageTemplate(MessageKind.DUPLICATED_LIBRARY_NAME,
1878 "Duplicated library name '#{libraryName}'."),
1879
1880 MessageKind.DUPLICATED_RESOURCE:
1881 const MessageTemplate(MessageKind.DUPLICATED_RESOURCE,
1882 "The resource '#{resourceUri}' is loaded through both "
1883 "'#{canonicalUri1}' and '#{canonicalUri2}'."),
1884
1885 MessageKind.DUPLICATED_LIBRARY_RESOURCE:
1886 const MessageTemplate(MessageKind.DUPLICATED_LIBRARY_RESOURCE,
1887 "The library '#{libraryName}' in '#{resourceUri}' is loaded through "
1888 "both '#{canonicalUri1}' and '#{canonicalUri2}'."),
1889
1890 // This is used as an exception.
1891 MessageKind.INVALID_SOURCE_FILE_LOCATION:
1892 const MessageTemplate(MessageKind.INVALID_SOURCE_FILE_LOCATION, '''
1893 Invalid offset (#{offset}) in source map.
1894 File: #{fileName}
1895 Length: #{length}'''),
1896
1897 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC:
1898 const MessageTemplate(MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC,
1899 "Top-level variable cannot be declared static."),
1900
1901 MessageKind.REFERENCE_IN_INITIALIZATION:
1902 const MessageTemplate(MessageKind.REFERENCE_IN_INITIALIZATION,
1903 "Variable '#{variableName}' is referenced during its "
1904 "initialization.",
1905 howToFix:
1906 "If you are trying to reference a shadowed variable, rename "
1907 "one of the variables.",
1908 examples: const ["""
1909 foo(t) {
1910 var t = t;
1911 return t;
1912 }
1913
1914 main() => foo(1);
1915 """]),
1916
1917 MessageKind.CONST_WITHOUT_INITIALIZER:
1918 const MessageTemplate(MessageKind.CONST_WITHOUT_INITIALIZER,
1919 "A constant variable must be initialized.",
1920 howToFix: "Try adding an initializer or "
1921 "removing the 'const' modifier.",
1922 examples: const ["""
1923 void main() {
1924 const c; // This constant variable must be initialized.
1925 }"""]),
1926
1927 MessageKind.FINAL_WITHOUT_INITIALIZER:
1928 const MessageTemplate(MessageKind.FINAL_WITHOUT_INITIALIZER,
1929 "A final variable must be initialized.",
1930 howToFix: "Try adding an initializer or "
1931 "removing the 'final' modifier.",
1932 examples: const [
1933 "class C { static final field; } main() => C.field;"]),
1934
1935 MessageKind.MEMBER_USES_CLASS_NAME:
1936 const MessageTemplate(MessageKind.MEMBER_USES_CLASS_NAME,
1937 "Member variable can't have the same name as the class it is "
1938 "declared in.",
1939 howToFix: "Try renaming the variable.",
1940 examples: const ["""
1941 class A { var A; }
1942 main() {
1943 var a = new A();
1944 a.A = 1;
1945 }
1946 """, """
1947 class A { static var A; }
1948 main() => A.A = 1;
1949 """]),
1950
1951 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT:
1952 const MessageTemplate(
1953 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT,
1954 "Wrong number of arguments to assert. Should be 1, but given "
1955 "#{argumentCount}."),
1956
1957 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS:
1958 const MessageTemplate(MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS,
1959 "'assert' takes no named arguments, but given #{argumentCount}."),
1960
1961 MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY:
1962 const MessageTemplate(MessageKind.FACTORY_REDIRECTION_IN_NON_FACTORY,
1963 "Factory redirection only allowed in factories."),
1964
1965 MessageKind.MISSING_FACTORY_KEYWORD:
1966 const MessageTemplate(MessageKind.MISSING_FACTORY_KEYWORD,
1967 "Did you forget a factory keyword here?"),
1968
1969 MessageKind.NO_SUCH_METHOD_IN_NATIVE:
1970 const MessageTemplate(MessageKind.NO_SUCH_METHOD_IN_NATIVE,
1971 "'NoSuchMethod' is not supported for classes that extend native "
1972 "classes."),
1973
1974 MessageKind.DEFERRED_LIBRARY_DART_2_DART:
1975 const MessageTemplate(MessageKind.DEFERRED_LIBRARY_DART_2_DART,
1976 "Deferred loading is not supported by the dart backend yet. "
1977 "The output will not be split."),
1978
1979 MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX:
1980 const MessageTemplate(MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX,
1981 "This import is deferred but there is no prefix keyword.",
1982 howToFix: "Try adding a prefix to the import."),
1983
1984 MessageKind.DEFERRED_OLD_SYNTAX:
1985 const MessageTemplate(MessageKind.DEFERRED_OLD_SYNTAX,
1986 "The DeferredLibrary annotation is obsolete.",
1987 howToFix:
1988 "Use the \"import 'lib.dart' deferred as prefix\" syntax instead."),
1989
1990 MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX:
1991 const MessageTemplate(MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX,
1992 "The prefix of this deferred import is not unique.",
1993 howToFix: "Try changing the import prefix."),
1994
1995 MessageKind.DEFERRED_TYPE_ANNOTATION:
1996 const MessageTemplate(MessageKind.DEFERRED_TYPE_ANNOTATION,
1997 "The type #{node} is deferred. "
1998 "Deferred types are not valid as type annotations.",
1999 howToFix:
2000 "Try using a non-deferred abstract class as an interface."),
2001
2002 MessageKind.ILLEGAL_STATIC:
2003 const MessageTemplate(MessageKind.ILLEGAL_STATIC,
2004 "Modifier static is only allowed on functions declared in "
2005 "a class."),
2006
2007 MessageKind.STATIC_FUNCTION_BLOAT:
2008 const MessageTemplate(MessageKind.STATIC_FUNCTION_BLOAT,
2009 "Using '#{class}.#{name}' may lead to unnecessarily large "
2010 "generated code.",
2011 howToFix:
2012 "Try adding '@MirrorsUsed(...)' as described at "
2013 "https://goo.gl/Akrrog."),
2014
2015 MessageKind.NON_CONST_BLOAT:
2016 const MessageTemplate(MessageKind.NON_CONST_BLOAT,
2017 "Using 'new #{name}' may lead to unnecessarily large generated "
2018 "code.",
2019 howToFix:
2020 "Try using 'const #{name}' or adding '@MirrorsUsed(...)' as "
2021 "described at https://goo.gl/Akrrog."),
2022
2023 MessageKind.STRING_EXPECTED:
2024 const MessageTemplate(MessageKind.STRING_EXPECTED,
2025 "Expected a 'String', but got an instance of '#{type}'."),
2026
2027 MessageKind.PRIVATE_IDENTIFIER:
2028 const MessageTemplate(MessageKind.PRIVATE_IDENTIFIER,
2029 "'#{value}' is not a valid Symbol name because it starts with "
2030 "'_'."),
2031
2032 MessageKind.PRIVATE_NAMED_PARAMETER:
2033 const MessageTemplate(MessageKind.PRIVATE_NAMED_PARAMETER,
2034 "Named optional parameter can't have a library private name.",
2035 howToFix:
2036 "Try removing the '_' or making the parameter positional or "
2037 "required.",
2038 examples: const ["""foo({int _p}) {} main() => foo();"""]),
2039
2040 MessageKind.UNSUPPORTED_LITERAL_SYMBOL:
2041 const MessageTemplate(MessageKind.UNSUPPORTED_LITERAL_SYMBOL,
2042 "Symbol literal '##{value}' is currently unsupported by dart2js."),
2043
2044 MessageKind.INVALID_SYMBOL:
2045 const MessageTemplate(MessageKind.INVALID_SYMBOL, '''
2046 '#{value}' is not a valid Symbol name because is not:
2047 * an empty String,
2048 * a user defined operator,
2049 * a qualified non-private identifier optionally followed by '=', or
2050 * a qualified non-private identifier followed by '.' and a user-defined '''
2051 "operator."),
2052
2053 MessageKind.AMBIGUOUS_REEXPORT:
2054 const MessageTemplate(MessageKind.AMBIGUOUS_REEXPORT,
2055 "'#{name}' is (re)exported by multiple libraries."),
2056
2057 MessageKind.AMBIGUOUS_LOCATION:
2058 const MessageTemplate(MessageKind.AMBIGUOUS_LOCATION,
2059 "'#{name}' is defined here."),
2060
2061 MessageKind.IMPORTED_HERE:
2062 const MessageTemplate(MessageKind.IMPORTED_HERE,
2063 "'#{name}' is imported here."),
2064
2065 MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE:
2066 const MessageTemplate(MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE,
2067 "The class '#{class}' overrides 'operator==', "
2068 "but not 'get hashCode'."),
2069
2070 MessageKind.INTERNAL_LIBRARY_FROM:
2071 const MessageTemplate(MessageKind.INTERNAL_LIBRARY_FROM,
2072 "Internal library '#{resolvedUri}' is not accessible from "
2073 "'#{importingUri}'."),
2074
2075 MessageKind.INTERNAL_LIBRARY:
2076 const MessageTemplate(MessageKind.INTERNAL_LIBRARY,
2077 "Internal library '#{resolvedUri}' is not accessible."),
2078
2079 MessageKind.LIBRARY_NOT_FOUND:
2080 const MessageTemplate(MessageKind.LIBRARY_NOT_FOUND,
2081 "Library not found '#{resolvedUri}'."),
2082
2083 MessageKind.UNSUPPORTED_EQ_EQ_EQ:
2084 const MessageTemplate(MessageKind.UNSUPPORTED_EQ_EQ_EQ,
2085 "'===' is not an operator. "
2086 "Did you mean '#{lhs} == #{rhs}' or 'identical(#{lhs}, #{rhs})'?"),
2087
2088 MessageKind.UNSUPPORTED_BANG_EQ_EQ:
2089 const MessageTemplate(MessageKind.UNSUPPORTED_BANG_EQ_EQ,
2090 "'!==' is not an operator. "
2091 "Did you mean '#{lhs} != #{rhs}' or '!identical(#{lhs}, #{rhs})'?"),
2092
2093 MessageKind.UNSUPPORTED_PREFIX_PLUS:
2094 const MessageTemplate(MessageKind.UNSUPPORTED_PREFIX_PLUS,
2095 "'+' is not a prefix operator. ",
2096 howToFix: "Try removing '+'.",
2097 examples: const [
2098 "main() => +2; // No longer a valid way to write '2'"
2099 ]),
2100
2101 MessageKind.UNSUPPORTED_THROW_WITHOUT_EXP:
2102 const MessageTemplate(MessageKind.UNSUPPORTED_THROW_WITHOUT_EXP,
2103 "No expression after 'throw'. "
2104 "Did you mean 'rethrow'?"),
2105
2106 MessageKind.DEPRECATED_TYPEDEF_MIXIN_SYNTAX:
2107 const MessageTemplate(MessageKind.DEPRECATED_TYPEDEF_MIXIN_SYNTAX,
2108 "'typedef' not allowed here. ",
2109 howToFix: "Try replacing 'typedef' with 'class'.",
2110 examples: const [
2111 """
2112 class B { }
2113 class M1 { }
2114 typedef C = B with M1; // Need to replace 'typedef' with 'class'.
2115 main() { new C(); }
2116 """]),
2117
2118 MessageKind.MIRRORS_EXPECTED_STRING:
2119 const MessageTemplate(MessageKind.MIRRORS_EXPECTED_STRING,
2120 "Can't use '#{name}' here because it's an instance of '#{type}' "
2121 "and a 'String' value is expected.",
2122 howToFix: "Did you forget to add quotes?",
2123 examples: const [
2124 """
2125 // 'Foo' is a type literal, not a string.
2126 @MirrorsUsed(symbols: const [Foo])
2127 import 'dart:mirrors';
2128
2129 class Foo {}
2130
2131 main() {}
2132 """]),
2133
2134 MessageKind.MIRRORS_EXPECTED_STRING_OR_TYPE:
2135 const MessageTemplate(MessageKind.MIRRORS_EXPECTED_STRING_OR_TYPE,
2136 "Can't use '#{name}' here because it's an instance of '#{type}' "
2137 "and a 'String' or 'Type' value is expected.",
2138 howToFix: "Did you forget to add quotes?",
2139 examples: const [
2140 """
2141 // 'main' is a method, not a class.
2142 @MirrorsUsed(targets: const [main])
2143 import 'dart:mirrors';
2144
2145 main() {}
2146 """]),
2147
2148 MessageKind.MIRRORS_EXPECTED_STRING_OR_LIST:
2149 const MessageTemplate(MessageKind.MIRRORS_EXPECTED_STRING_OR_LIST,
2150 "Can't use '#{name}' here because it's an instance of '#{type}' "
2151 "and a 'String' or 'List' value is expected.",
2152 howToFix: "Did you forget to add quotes?",
2153 examples: const [
2154 """
2155 // 'Foo' is not a string.
2156 @MirrorsUsed(symbols: Foo)
2157 import 'dart:mirrors';
2158
2159 class Foo {}
2160
2161 main() {}
2162 """]),
2163
2164 MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST:
2165 const MessageTemplate(MessageKind.MIRRORS_EXPECTED_STRING_TYPE_OR_LIST,
2166 "Can't use '#{name}' here because it's an instance of '#{type}' "
2167 "but a 'String', 'Type', or 'List' value is expected.",
2168 howToFix: "Did you forget to add quotes?",
2169 examples: const [
2170 """
2171 // '1' is not a string.
2172 @MirrorsUsed(targets: 1)
2173 import 'dart:mirrors';
2174
2175 main() {}
2176 """]),
2177
2178 MessageKind.MIRRORS_CANNOT_RESOLVE_IN_CURRENT_LIBRARY:
2179 const MessageTemplate(
2180 MessageKind.MIRRORS_CANNOT_RESOLVE_IN_CURRENT_LIBRARY,
2181 "Can't find '#{name}' in the current library.",
2182 // TODO(ahe): The closest identifiers in edit distance would be nice.
2183 howToFix: "Did you forget to add an import?",
2184 examples: const [
2185 """
2186 // 'window' is not in scope because dart:html isn't imported.
2187 @MirrorsUsed(targets: 'window')
2188 import 'dart:mirrors';
2189
2190 main() {}
2191 """]),
2192
2193 MessageKind.MIRRORS_CANNOT_RESOLVE_IN_LIBRARY:
2194 const MessageTemplate(MessageKind.MIRRORS_CANNOT_RESOLVE_IN_LIBRARY,
2195 "Can't find '#{name}' in the library '#{library}'.",
2196 // TODO(ahe): The closest identifiers in edit distance would be nice.
2197 howToFix: "Is '#{name}' spelled right?",
2198 examples: const [
2199 """
2200 // 'List' is misspelled.
2201 @MirrorsUsed(targets: 'dart.core.Lsit')
2202 import 'dart:mirrors';
2203
2204 main() {}
2205 """]),
2206
2207 MessageKind.MIRRORS_CANNOT_FIND_IN_ELEMENT:
2208 const MessageTemplate(MessageKind.MIRRORS_CANNOT_FIND_IN_ELEMENT,
2209 "Can't find '#{name}' in '#{element}'.",
2210 // TODO(ahe): The closest identifiers in edit distance would be nice.
2211 howToFix: "Is '#{name}' spelled right?",
2212 examples: const [
2213 """
2214 // 'addAll' is misspelled.
2215 @MirrorsUsed(targets: 'dart.core.List.addAl')
2216 import 'dart:mirrors';
2217
2218 main() {}
2219 """]),
2220
2221 MessageKind.INVALID_URI:
2222 const MessageTemplate(MessageKind.INVALID_URI,
2223 "'#{uri}' is not a valid URI.",
2224 howToFix: DONT_KNOW_HOW_TO_FIX,
2225 examples: const [
2226 """
2227 // can't have a '[' in a URI
2228 import '../../Udyn[mic ils/expect.dart';
2229
2230 main() {}
2231 """]),
2232
2233 MessageKind.INVALID_PACKAGE_URI:
2234 const MessageTemplate(MessageKind.INVALID_PACKAGE_URI,
2235 "'#{uri}' is not a valid package URI (#{exception}).",
2236 howToFix: DONT_KNOW_HOW_TO_FIX,
2237 examples: const [
2238 """
2239 // can't have a 'top level' package URI
2240 import 'package:foo.dart';
2241
2242 main() {}
2243 """, """
2244 // can't have 2 slashes
2245 import 'package://foo/foo.dart';
2246
2247 main() {}
2248 """, """
2249 // package name must be valid
2250 import 'package:not\valid/foo.dart';
2251
2252 main() {}
2253 """]),
2254
2255 MessageKind.READ_SCRIPT_ERROR:
2256 const MessageTemplate(MessageKind.READ_SCRIPT_ERROR,
2257 "Can't read '#{uri}' (#{exception}).",
2258 // Don't know how to fix since the underlying error is unknown.
2259 howToFix: DONT_KNOW_HOW_TO_FIX,
2260 examples: const [
2261 """
2262 // 'foo.dart' does not exist.
2263 import 'foo.dart';
2264
2265 main() {}
2266 """]),
2267
2268 MessageKind.READ_SELF_ERROR:
2269 const MessageTemplate(MessageKind.READ_SELF_ERROR,
2270 "#{exception}",
2271 // Don't know how to fix since the underlying error is unknown.
2272 howToFix: DONT_KNOW_HOW_TO_FIX),
2273
2274 MessageKind.EXTRANEOUS_MODIFIER:
2275 const MessageTemplate(MessageKind.EXTRANEOUS_MODIFIER,
2276 "Can't have modifier '#{modifier}' here.",
2277 howToFix: "Try removing '#{modifier}'.",
2278 examples: const [
2279 "var String foo; main(){}",
2280 // "var get foo; main(){}",
2281 "var set foo; main(){}",
2282 "var final foo; main(){}",
2283 "var var foo; main(){}",
2284 "var const foo; main(){}",
2285 "var abstract foo; main(){}",
2286 "var static foo; main(){}",
2287 "var external foo; main(){}",
2288 "get var foo; main(){}",
2289 "set var foo; main(){}",
2290 "final var foo; main(){}",
2291 "var var foo; main(){}",
2292 "const var foo; main(){}",
2293 "abstract var foo; main(){}",
2294 "static var foo; main(){}",
2295 "external var foo; main(){}"]),
2296
2297 MessageKind.EXTRANEOUS_MODIFIER_REPLACE:
2298 const MessageTemplate(MessageKind.EXTRANEOUS_MODIFIER_REPLACE,
2299 "Can't have modifier '#{modifier}' here.",
2300 howToFix:
2301 "Try replacing modifier '#{modifier}' with 'var', 'final', "
2302 "or a type.",
2303 examples: const [
2304 // "get foo; main(){}",
2305 "set foo; main(){}",
2306 "abstract foo; main(){}",
2307 "static foo; main(){}",
2308 "external foo; main(){}"]),
2309
2310 MessageKind.ABSTRACT_CLASS_INSTANTIATION:
2311 const MessageTemplate(MessageKind.ABSTRACT_CLASS_INSTANTIATION,
2312 "Can't instantiate abstract class.",
2313 howToFix: DONT_KNOW_HOW_TO_FIX,
2314 examples: const ["abstract class A {} main() { new A(); }"]),
2315
2316 MessageKind.BODY_EXPECTED:
2317 const MessageTemplate(MessageKind.BODY_EXPECTED,
2318 "Expected a function body or '=>'.",
2319 // TODO(ahe): In some scenarios, we can suggest removing the 'static'
2320 // keyword.
2321 howToFix: "Try adding {}.",
2322 examples: const [
2323 "main();"]),
2324
2325 MessageKind.MIRROR_BLOAT:
2326 const MessageTemplate(MessageKind.MIRROR_BLOAT,
2327 "#{count} methods retained for use by dart:mirrors out of #{total}"
2328 " total methods (#{percentage}%)."),
2329
2330 MessageKind.MIRROR_IMPORT:
2331 const MessageTemplate(MessageKind.MIRROR_IMPORT,
2332 "Import of 'dart:mirrors'."),
2333
2334 MessageKind.MIRROR_IMPORT_NO_USAGE:
2335 const MessageTemplate(MessageKind.MIRROR_IMPORT_NO_USAGE,
2336 "This import is not annotated with @MirrorsUsed, which may lead to "
2337 "unnecessarily large generated code.",
2338 howToFix:
2339 "Try adding '@MirrorsUsed(...)' as described at "
2340 "https://goo.gl/Akrrog."),
2341
2342 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT:
2343 const MessageTemplate(
2344 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT,
2345 "Argument for 'JS_INTERCEPTOR_CONSTANT' must be a type constant."),
2346
2347 MessageKind.EXPECTED_IDENTIFIER_NOT_RESERVED_WORD:
2348 const MessageTemplate(MessageKind.EXPECTED_IDENTIFIER_NOT_RESERVED_WORD,
2349 "'#{keyword}' is a reserved word and can't be used here.",
2350 howToFix: "Try using a different name.",
2351 examples: const ["do() {} main() {}"]),
2352
2353 MessageKind. NAMED_FUNCTION_EXPRESSION:
2354 const MessageTemplate(MessageKind.NAMED_FUNCTION_EXPRESSION,
2355 "Function expression '#{name}' cannot be named.",
2356 howToFix: "Try removing the name.",
2357 examples: const ["main() { var f = func() {}; }"]),
2358
2359 MessageKind.UNUSED_METHOD:
2360 const MessageTemplate(MessageKind.UNUSED_METHOD,
2361 "The method '#{name}' is never called.",
2362 howToFix: "Consider deleting it.",
2363 examples: const ["deadCode() {} main() {}"]),
2364
2365 MessageKind.UNUSED_CLASS:
2366 const MessageTemplate(MessageKind.UNUSED_CLASS,
2367 "The class '#{name}' is never used.",
2368 howToFix: "Consider deleting it.",
2369 examples: const ["class DeadCode {} main() {}"]),
2370
2371 MessageKind.UNUSED_TYPEDEF:
2372 const MessageTemplate(MessageKind.UNUSED_TYPEDEF,
2373 "The typedef '#{name}' is never used.",
2374 howToFix: "Consider deleting it.",
2375 examples: const ["typedef DeadCode(); main() {}"]),
2376
2377 MessageKind.ABSTRACT_METHOD:
2378 const MessageTemplate(MessageKind.ABSTRACT_METHOD,
2379 "The method '#{name}' has no implementation in "
2380 "class '#{class}'.",
2381 howToFix: "Try adding a body to '#{name}' or declaring "
2382 "'#{class}' to be 'abstract'.",
2383 examples: const ["""
2384 class Class {
2385 method();
2386 }
2387 main() => new Class().method();
2388 """]),
2389
2390 MessageKind.ABSTRACT_GETTER:
2391 const MessageTemplate(MessageKind.ABSTRACT_GETTER,
2392 "The getter '#{name}' has no implementation in "
2393 "class '#{class}'.",
2394 howToFix: "Try adding a body to '#{name}' or declaring "
2395 "'#{class}' to be 'abstract'.",
2396 examples: const ["""
2397 class Class {
2398 get getter;
2399 }
2400 main() => new Class();
2401 """]),
2402
2403 MessageKind.ABSTRACT_SETTER:
2404 const MessageTemplate(MessageKind.ABSTRACT_SETTER,
2405 "The setter '#{name}' has no implementation in "
2406 "class '#{class}'.",
2407 howToFix: "Try adding a body to '#{name}' or declaring "
2408 "'#{class}' to be 'abstract'.",
2409 examples: const ["""
2410 class Class {
2411 set setter(_);
2412 }
2413 main() => new Class();
2414 """]),
2415
2416 MessageKind.INHERIT_GETTER_AND_METHOD:
2417 const MessageTemplate(MessageKind.INHERIT_GETTER_AND_METHOD,
2418 "The class '#{class}' can't inherit both getters and methods "
2419 "by the named '#{name}'.",
2420 howToFix: DONT_KNOW_HOW_TO_FIX,
2421 examples: const ["""
2422 class A {
2423 get member => null;
2424 }
2425 class B {
2426 member() {}
2427 }
2428 class Class implements A, B {
2429 }
2430 main() => new Class();
2431 """]),
2432
2433 MessageKind.INHERITED_METHOD:
2434 const MessageTemplate(MessageKind.INHERITED_METHOD,
2435 "The inherited method '#{name}' is declared here in class "
2436 "'#{class}'."),
2437
2438 MessageKind.INHERITED_EXPLICIT_GETTER:
2439 const MessageTemplate(MessageKind.INHERITED_EXPLICIT_GETTER,
2440 "The inherited getter '#{name}' is declared here in class "
2441 "'#{class}'."),
2442
2443 MessageKind.INHERITED_IMPLICIT_GETTER:
2444 const MessageTemplate(MessageKind.INHERITED_IMPLICIT_GETTER,
2445 "The inherited getter '#{name}' is implicitly declared by this "
2446 "field in class '#{class}'."),
2447
2448 MessageKind.UNIMPLEMENTED_METHOD_ONE:
2449 const MessageTemplate(MessageKind.UNIMPLEMENTED_METHOD_ONE,
2450 "'#{class}' doesn't implement '#{method}' "
2451 "declared in '#{declarer}'.",
2452 howToFix: "Try adding an implementation of '#{name}' or declaring "
2453 "'#{class}' to be 'abstract'.",
2454 examples: const ["""
2455 abstract class I {
2456 m();
2457 }
2458 class C implements I {}
2459 main() => new C();
2460 """, """
2461 abstract class I {
2462 m();
2463 }
2464 class C extends I {}
2465 main() => new C();
2466 """]),
2467
2468 MessageKind.UNIMPLEMENTED_METHOD:
2469 const MessageTemplate(MessageKind.UNIMPLEMENTED_METHOD,
2470 "'#{class}' doesn't implement '#{method}'.",
2471 howToFix: "Try adding an implementation of '#{name}' or declaring "
2472 "'#{class}' to be 'abstract'.",
2473 examples: const ["""
2474 abstract class I {
2475 m();
2476 }
2477
2478 abstract class J {
2479 m();
2480 }
2481
2482 class C implements I, J {}
2483
2484 main() {
2485 new C();
2486 }
2487 """, """
2488 abstract class I {
2489 m();
2490 }
2491
2492 abstract class J {
2493 m();
2494 }
2495
2496 class C extends I implements J {}
2497
2498 main() {
2499 new C();
2500 }
2501 """]),
2502
2503 MessageKind.UNIMPLEMENTED_METHOD_CONT:
2504 const MessageTemplate(MessageKind.UNIMPLEMENTED_METHOD_CONT,
2505 "The method '#{name}' is declared here in class '#{class}'."),
2506
2507 MessageKind.UNIMPLEMENTED_SETTER_ONE:
2508 const MessageTemplate(MessageKind.UNIMPLEMENTED_SETTER_ONE,
2509 "'#{class}' doesn't implement the setter '#{name}' "
2510 "declared in '#{declarer}'.",
2511 howToFix: "Try adding an implementation of '#{name}' or declaring "
2512 "'#{class}' to be 'abstract'.",
2513 examples: const ["""
2514 abstract class I {
2515 set m(_);
2516 }
2517 class C implements I {}
2518 class D implements I {
2519 set m(_) {}
2520 }
2521 main() {
2522 new D().m = 0;
2523 new C();
2524 }
2525 """]),
2526
2527 MessageKind.UNIMPLEMENTED_SETTER:
2528 const MessageTemplate(MessageKind.UNIMPLEMENTED_SETTER,
2529 "'#{class}' doesn't implement the setter '#{name}'.",
2530 howToFix: "Try adding an implementation of '#{name}' or declaring "
2531 "'#{class}' to be 'abstract'.",
2532 examples: const ["""
2533 abstract class I {
2534 set m(_);
2535 }
2536 abstract class J {
2537 set m(_);
2538 }
2539 class C implements I, J {}
2540 main() => new C();
2541 """, """
2542 abstract class I {
2543 set m(_);
2544 }
2545 abstract class J {
2546 set m(_);
2547 }
2548 class C extends I implements J {}
2549 main() => new C();
2550 """]),
2551
2552 MessageKind.UNIMPLEMENTED_EXPLICIT_SETTER:
2553 const MessageTemplate(MessageKind.UNIMPLEMENTED_EXPLICIT_SETTER,
2554 "The setter '#{name}' is declared here in class '#{class}'."),
2555
2556 MessageKind.UNIMPLEMENTED_IMPLICIT_SETTER:
2557 const MessageTemplate(MessageKind.UNIMPLEMENTED_IMPLICIT_SETTER,
2558 "The setter '#{name}' is implicitly declared by this field "
2559 "in class '#{class}'."),
2560
2561 MessageKind.UNIMPLEMENTED_GETTER_ONE:
2562 const MessageTemplate(MessageKind.UNIMPLEMENTED_GETTER_ONE,
2563 "'#{class}' doesn't implement the getter '#{name}' "
2564 "declared in '#{declarer}'.",
2565 howToFix: "Try adding an implementation of '#{name}' or declaring "
2566 "'#{class}' to be 'abstract'.",
2567 examples: const ["""
2568 abstract class I {
2569 get m;
2570 }
2571 class C implements I {}
2572 main() => new C();
2573 """, """
2574 abstract class I {
2575 get m;
2576 }
2577 class C extends I {}
2578 main() => new C();
2579 """]),
2580
2581 MessageKind.UNIMPLEMENTED_GETTER:
2582 const MessageTemplate(MessageKind.UNIMPLEMENTED_GETTER,
2583 "'#{class}' doesn't implement the getter '#{name}'.",
2584 howToFix: "Try adding an implementation of '#{name}' or declaring "
2585 "'#{class}' to be 'abstract'.",
2586 examples: const ["""
2587 abstract class I {
2588 get m;
2589 }
2590 abstract class J {
2591 get m;
2592 }
2593 class C implements I, J {}
2594 main() => new C();
2595 """, """
2596 abstract class I {
2597 get m;
2598 }
2599 abstract class J {
2600 get m;
2601 }
2602 class C extends I implements J {}
2603 main() => new C();
2604 """]),
2605
2606 MessageKind.UNIMPLEMENTED_EXPLICIT_GETTER:
2607 const MessageTemplate(MessageKind.UNIMPLEMENTED_EXPLICIT_GETTER,
2608 "The getter '#{name}' is declared here in class '#{class}'."),
2609
2610 MessageKind.UNIMPLEMENTED_IMPLICIT_GETTER:
2611 const MessageTemplate(MessageKind.UNIMPLEMENTED_IMPLICIT_GETTER,
2612 "The getter '#{name}' is implicitly declared by this field "
2613 "in class '#{class}'."),
2614
2615 MessageKind.EQUAL_MAP_ENTRY_KEY:
2616 const MessageTemplate(MessageKind.EQUAL_MAP_ENTRY_KEY,
2617 "An entry with the same key already exists in the map.",
2618 howToFix:
2619 "Try removing the previous entry or changing the key in one "
2620 "of the entries.",
2621 examples: const ["""
2622 main() {
2623 var m = const {'foo': 1, 'foo': 2};
2624 }"""]),
2625
2626 MessageKind.BAD_INPUT_CHARACTER:
2627 const MessageTemplate(MessageKind.BAD_INPUT_CHARACTER,
2628 "Character U+#{characterHex} isn't allowed here.",
2629 howToFix: DONT_KNOW_HOW_TO_FIX,
2630 examples: const ["""
2631 main() {
2632 String x = ç;
2633 }
2634 """]),
2635
2636 MessageKind.UNTERMINATED_STRING:
2637 const MessageTemplate(MessageKind.UNTERMINATED_STRING,
2638 "String must end with #{quote}.",
2639 howToFix: DONT_KNOW_HOW_TO_FIX,
2640 examples: const ["""
2641 main() {
2642 return '
2643 ;
2644 }
2645 """,
2646 """
2647 main() {
2648 return \"
2649 ;
2650 }
2651 """,
2652 """
2653 main() {
2654 return r'
2655 ;
2656 }
2657 """,
2658 """
2659 main() {
2660 return r\"
2661 ;
2662 }
2663 """,
2664 """
2665 main() => '''
2666 """,
2667 """
2668 main() => \"\"\"
2669 """,
2670 """
2671 main() => r'''
2672 """,
2673 """
2674 main() => r\"\"\"
2675 """]),
2676
2677 MessageKind.UNMATCHED_TOKEN:
2678 const MessageTemplate(MessageKind.UNMATCHED_TOKEN,
2679 "Can't find '#{end}' to match '#{begin}'.",
2680 howToFix: DONT_KNOW_HOW_TO_FIX,
2681 examples: const[
2682 "main(",
2683 "main(){",
2684 "main(){]}",
2685 ]),
2686
2687 MessageKind.UNTERMINATED_TOKEN:
2688 const MessageTemplate(MessageKind.UNTERMINATED_TOKEN,
2689 // This is a fall-back message that shouldn't happen.
2690 "Incomplete token."),
2691
2692 MessageKind.EXPONENT_MISSING:
2693 const MessageTemplate(MessageKind.EXPONENT_MISSING,
2694 "Numbers in exponential notation should always contain an exponent"
2695 " (an integer number with an optional sign).",
2696 howToFix:
2697 "Make sure there is an exponent, and remove any whitespace "
2698 "before it.",
2699 examples: const ["""
2700 main() {
2701 var i = 1e;
2702 }
2703 """]),
2704
2705 MessageKind.HEX_DIGIT_EXPECTED:
2706 const MessageTemplate(MessageKind.HEX_DIGIT_EXPECTED,
2707 "A hex digit (0-9 or A-F) must follow '0x'.",
2708 howToFix:
2709 DONT_KNOW_HOW_TO_FIX, // Seems obvious from the error message.
2710 examples: const ["""
2711 main() {
2712 var i = 0x;
2713 }
2714 """]),
2715
2716 MessageKind.MALFORMED_STRING_LITERAL:
2717 const MessageTemplate(MessageKind.MALFORMED_STRING_LITERAL,
2718 r"A '$' has special meaning inside a string, and must be followed by "
2719 "an identifier or an expression in curly braces ({}).",
2720 howToFix: r"Try adding a backslash (\) to escape the '$'.",
2721 examples: const [r"""
2722 main() {
2723 return '$';
2724 }
2725 """,
2726 r'''
2727 main() {
2728 return "$";
2729 }
2730 ''',
2731 r"""
2732 main() {
2733 return '''$''';
2734 }
2735 """,
2736 r'''
2737 main() {
2738 return """$""";
2739 }
2740 ''']),
2741
2742 MessageKind.UNTERMINATED_COMMENT:
2743 const MessageTemplate(MessageKind.UNTERMINATED_COMMENT,
2744 "Comment starting with '/*' must end with '*/'.",
2745 howToFix: DONT_KNOW_HOW_TO_FIX,
2746 examples: const [r"""
2747 main() {
2748 }
2749 /*"""]),
2750
2751 MessageKind.MISSING_TOKEN_BEFORE_THIS:
2752 const MessageTemplate(MessageKind.MISSING_TOKEN_BEFORE_THIS,
2753 "Expected '#{token}' before this.",
2754 // Consider the second example below: the parser expects a ')' before
2755 // 'y', but a ',' would also have worked. We don't have enough
2756 // information to give a good suggestion.
2757 howToFix: DONT_KNOW_HOW_TO_FIX,
2758 examples: const [
2759 "main() => true ? 1;",
2760 "main() => foo(x: 1 y: 2);",
2761 ]),
2762
2763 MessageKind.MISSING_TOKEN_AFTER_THIS:
2764 const MessageTemplate(MessageKind.MISSING_TOKEN_AFTER_THIS,
2765 "Expected '#{token}' after this.",
2766 // See [MISSING_TOKEN_BEFORE_THIS], we don't have enough information
2767 // to give a good suggestion.
2768 howToFix: DONT_KNOW_HOW_TO_FIX,
2769 examples: const [
2770 "main(x) {x}",
2771 """
2772 class S1 {}
2773 class S2 {}
2774 class S3 {}
2775 class A = S1 with S2, S3
2776 main() => new A();
2777 """
2778 ]),
2779
2780 MessageKind.CONSIDER_ANALYZE_ALL:
2781 const MessageTemplate(MessageKind.CONSIDER_ANALYZE_ALL,
2782 "Could not find '#{main}'. Nothing will be analyzed.",
2783 howToFix: "Try using '--analyze-all' to analyze everything.",
2784 examples: const ['']),
2785
2786 MessageKind.MISSING_MAIN:
2787 const MessageTemplate(MessageKind.MISSING_MAIN,
2788 "Could not find '#{main}'.",
2789 howToFix: "Try adding a method named '#{main}' to your program."
2790 /* No example, test uses '--analyze-only' which will produce the above
2791 * message [CONSIDER_ANALYZE_ALL]. An example for a human operator
2792 * would be an empty file.*/),
2793
2794 MessageKind.MAIN_NOT_A_FUNCTION:
2795 const MessageTemplate(MessageKind.MAIN_NOT_A_FUNCTION,
2796 "'#{main}' is not a function.",
2797 howToFix: DONT_KNOW_HOW_TO_FIX, /* Don't state the obvious. */
2798 examples: const ['var main;']),
2799
2800 MessageKind.MAIN_WITH_EXTRA_PARAMETER:
2801 const MessageTemplate(MessageKind.MAIN_WITH_EXTRA_PARAMETER,
2802 "'#{main}' cannot have more than two parameters.",
2803 howToFix: DONT_KNOW_HOW_TO_FIX, /* Don't state the obvious. */
2804 examples: const ['main(a, b, c) {}']),
2805
2806 MessageKind.COMPILER_CRASHED:
2807 const MessageTemplate(MessageKind.COMPILER_CRASHED,
2808 "The compiler crashed when compiling this element."),
2809
2810 MessageKind.PLEASE_REPORT_THE_CRASH:
2811 const MessageTemplate(MessageKind.PLEASE_REPORT_THE_CRASH, '''
2812 The compiler is broken.
2813
2814 When compiling the above element, the compiler crashed. It is not
2815 possible to tell if this is caused by a problem in your program or
2816 not. Regardless, the compiler should not crash.
2817
2818 The Dart team would greatly appreciate if you would take a moment to
2819 report this problem at http://dartbug.com/new.
2820
2821 Please include the following information:
2822
2823 * the name and version of your operating system,
2824
2825 * the Dart SDK build number (#{buildId}), and
2826
2827 * the entire message you see here (including the full stack trace
2828 below as well as the source location above).
2829 '''),
2830
2831 MessageKind.POTENTIAL_MUTATION:
2832 const MessageTemplate(MessageKind.POTENTIAL_MUTATION,
2833 "Variable '#{variableName}' is not known to be of type "
2834 "'#{shownType}' because it is potentially mutated in the scope for "
2835 "promotion."),
2836
2837 MessageKind.POTENTIAL_MUTATION_HERE:
2838 const MessageTemplate(MessageKind.POTENTIAL_MUTATION_HERE,
2839 "Variable '#{variableName}' is potentially mutated here."),
2840
2841 MessageKind.POTENTIAL_MUTATION_IN_CLOSURE:
2842 const MessageTemplate(MessageKind.POTENTIAL_MUTATION_IN_CLOSURE,
2843 "Variable '#{variableName}' is not known to be of type "
2844 "'#{shownType}' because it is potentially mutated within a closure."),
2845
2846 MessageKind.POTENTIAL_MUTATION_IN_CLOSURE_HERE:
2847 const MessageTemplate(MessageKind.POTENTIAL_MUTATION_IN_CLOSURE_HERE,
2848 "Variable '#{variableName}' is potentially mutated in a "
2849 "closure here."),
2850
2851 MessageKind.ACCESSED_IN_CLOSURE:
2852 const MessageTemplate(MessageKind.ACCESSED_IN_CLOSURE,
2853 "Variable '#{variableName}' is not known to be of type "
2854 "'#{shownType}' because it is accessed by a closure in the scope for "
2855 "promotion and potentially mutated in the scope of "
2856 "'#{variableName}'."),
2857
2858 MessageKind.ACCESSED_IN_CLOSURE_HERE:
2859 const MessageTemplate(MessageKind.ACCESSED_IN_CLOSURE_HERE,
2860 "Variable '#{variableName}' is accessed in a closure here."),
2861
2862 MessageKind.NOT_MORE_SPECIFIC:
2863 const MessageTemplate(MessageKind.NOT_MORE_SPECIFIC,
2864 "Variable '#{variableName}' is not shown to have type "
2865 "'#{shownType}' because '#{shownType}' is not more specific than the "
2866 "known type '#{knownType}' of '#{variableName}'."),
2867
2868 MessageKind.NOT_MORE_SPECIFIC_SUBTYPE:
2869 const MessageTemplate(MessageKind.NOT_MORE_SPECIFIC_SUBTYPE,
2870 "Variable '#{variableName}' is not shown to have type "
2871 "'#{shownType}' because '#{shownType}' is not a subtype of the "
2872 "known type '#{knownType}' of '#{variableName}'."),
2873
2874 MessageKind.NOT_MORE_SPECIFIC_SUGGESTION:
2875 const MessageTemplate(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION,
2876 "Variable '#{variableName}' is not shown to have type "
2877 "'#{shownType}' because '#{shownType}' is not more specific than the "
2878 "known type '#{knownType}' of '#{variableName}'.",
2879 howToFix:
2880 "Try replacing '#{shownType}' with '#{shownTypeSuggestion}'."),
2881
2882 MessageKind.HIDDEN_WARNINGS_HINTS:
2883 const MessageTemplate(MessageKind.HIDDEN_WARNINGS_HINTS,
2884 "#{warnings} warning(s) and #{hints} hint(s) suppressed in #{uri}."),
2885
2886 MessageKind.HIDDEN_WARNINGS:
2887 const MessageTemplate(MessageKind.HIDDEN_WARNINGS,
2888 "#{warnings} warning(s) suppressed in #{uri}."),
2889
2890 MessageKind.HIDDEN_HINTS:
2891 const MessageTemplate(MessageKind.HIDDEN_HINTS,
2892 "#{hints} hint(s) suppressed in #{uri}."),
2893
2894 MessageKind.PREAMBLE:
2895 const MessageTemplate(MessageKind.PREAMBLE,
2896 "When run on the command-line, the compiled output might"
2897 " require a preamble file located in:\n"
2898 " <sdk>/lib/_internal/js_runtime/lib/preambles."),
2899
2900 MessageKind.INVALID_SYNC_MODIFIER:
2901 const MessageTemplate(MessageKind.INVALID_SYNC_MODIFIER,
2902 "Invalid modifier 'sync'.",
2903 options: const ['--enable-async'],
2904 howToFix: "Try replacing 'sync' with 'sync*'.",
2905 examples: const [
2906 "main() sync {}"
2907 ]),
2908
2909 MessageKind.INVALID_AWAIT_FOR:
2910 const MessageTemplate(MessageKind.INVALID_AWAIT_FOR,
2911 "'await' is only supported on for-in loops.",
2912 options: const ['--enable-async'],
2913 howToFix: "Try rewriting the loop as a for-in loop or removing the "
2914 "'await' keyword.",
2915 examples: const ["""
2916 main() async* {
2917 await for (int i = 0; i < 10; i++) {}
2918 }
2919 """]),
2920
2921 MessageKind.ASYNC_MODIFIER_ON_ABSTRACT_METHOD:
2922 const MessageTemplate(MessageKind.ASYNC_MODIFIER_ON_ABSTRACT_METHOD,
2923 "The modifier '#{modifier}' is not allowed on an abstract method.",
2924 options: const ['--enable-async'],
2925 howToFix: "Try removing the '#{modifier}' modifier or adding a "
2926 "body to the method.",
2927 examples: const ["""
2928 abstract class A {
2929 method() async;
2930 }
2931 class B extends A {
2932 method() {}
2933 }
2934 main() {
2935 A a = new B();
2936 a.method();
2937 }
2938 """]),
2939
2940 MessageKind.ASYNC_MODIFIER_ON_CONSTRUCTOR:
2941 const MessageTemplate(MessageKind.ASYNC_MODIFIER_ON_CONSTRUCTOR,
2942 "The modifier '#{modifier}' is not allowed on constructors.",
2943 options: const ['--enable-async'],
2944 howToFix: "Try removing the '#{modifier}' modifier.",
2945 examples: const ["""
2946 class A {
2947 A() async;
2948 }
2949 main() => new A();""",
2950
2951 """
2952 class A {
2953 A();
2954 factory A.a() async* {}
2955 }
2956 main() => new A.a();"""]),
2957
2958 MessageKind.ASYNC_MODIFIER_ON_SETTER:
2959 const MessageTemplate(MessageKind.ASYNC_MODIFIER_ON_SETTER,
2960 "The modifier '#{modifier}' is not allowed on setters.",
2961 options: const ['--enable-async'],
2962 howToFix: "Try removing the '#{modifier}' modifier.",
2963 examples: const ["""
2964 class A {
2965 set foo(v) async {}
2966 }
2967 main() => new A().foo = 0;"""]),
2968
2969 MessageKind.YIELDING_MODIFIER_ON_ARROW_BODY:
2970 const MessageTemplate(MessageKind.YIELDING_MODIFIER_ON_ARROW_BODY,
2971 "The modifier '#{modifier}' is not allowed on methods implemented "
2972 "using '=>'.",
2973 options: const ['--enable-async'],
2974 howToFix: "Try removing the '#{modifier}' modifier or implementing "
2975 "the method body using a block: '{ ... }'.",
2976 examples: const ["main() sync* => null;", "main() async* => null;"]),
2977
2978 // TODO(johnniwinther): Check for 'async' as identifier.
2979 MessageKind.ASYNC_KEYWORD_AS_IDENTIFIER:
2980 const MessageTemplate(MessageKind.ASYNC_KEYWORD_AS_IDENTIFIER,
2981 "'#{keyword}' cannot be used as an identifier in a function body "
2982 "marked with '#{modifier}'.",
2983 options: const ['--enable-async'],
2984 howToFix: "Try removing the '#{modifier}' modifier or renaming the "
2985 "identifier.",
2986 examples: const ["""
2987 main() async {
2988 var await;
2989 }""",
2990 """
2991 main() async* {
2992 var yield;
2993 }""",
2994 """
2995 main() sync* {
2996 var yield;
2997 }"""]),
2998
2999 MessageKind.RETURN_IN_GENERATOR:
3000 const MessageTemplate(MessageKind.RETURN_IN_GENERATOR,
3001 "'return' with a value is not allowed in a method body using the "
3002 "'#{modifier}' modifier.",
3003 howToFix: "Try removing the value, replacing 'return' with 'yield' "
3004 "or changing the method body modifier.",
3005 examples: const [
3006 """
3007 foo() async* { return 0; }
3008 main() => foo();
3009 """,
3010
3011 """
3012 foo() sync* { return 0; }
3013 main() => foo();
3014 """]),
3015
3016 MessageKind.NATIVE_NOT_SUPPORTED:
3017 const MessageTemplate(MessageKind.NATIVE_NOT_SUPPORTED,
3018 "'native' modifier is not supported.",
3019 howToFix: "Try removing the 'native' implementation or analyzing the "
3020 "code with the --allow-native-extensions option.",
3021 examples: const ["""
3022 main() native "Main";
3023 """]),
3024
3025 MessageKind.DART_EXT_NOT_SUPPORTED:
3026 const MessageTemplate(MessageKind.DART_EXT_NOT_SUPPORTED,
3027 "The 'dart-ext' scheme is not supported.",
3028 howToFix: "Try analyzing the code with the --allow-native-extensions "
3029 "option.",
3030 examples: const ["""
3031 import 'dart-ext:main';
3032
3033 main() {}
3034 """]),
3035
3036 MessageKind.LIBRARY_TAG_MUST_BE_FIRST:
3037 const MessageTemplate(MessageKind.LIBRARY_TAG_MUST_BE_FIRST,
3038 "The library declaration should come before other declarations.",
3039 howToFix: "Try moving the declaration to the top of the file.",
3040 examples: const [
3041 """
3042 import 'dart:core';
3043 library foo;
3044 main() {}
3045 """,
3046 ]),
3047
3048 MessageKind.ONLY_ONE_LIBRARY_TAG:
3049 const MessageTemplate(MessageKind.ONLY_ONE_LIBRARY_TAG,
3050 "There can only be one library declaration.",
3051 howToFix: "Try removing all other library declarations.",
3052 examples: const [
3053 """
3054 library foo;
3055 library bar;
3056 main() {}
3057 """,
3058 """
3059 library foo;
3060 import 'dart:core';
3061 library bar;
3062 main() {}
3063 """,
3064 ]),
3065
3066 MessageKind.IMPORT_BEFORE_PARTS:
3067 const MessageTemplate(MessageKind.IMPORT_BEFORE_PARTS,
3068 "Import declarations should come before parts.",
3069 howToFix: "Try moving this import further up in the file.",
3070 examples: const [
3071 const <String, String>{
3072 'main.dart': """
3073 library test.main;
3074 part 'part.dart';
3075 import 'dart:core';
3076 main() {}
3077 """,
3078 'part.dart': """
3079 part of test.main;
3080 """,
3081 }]),
3082
3083 MessageKind.EXPORT_BEFORE_PARTS:
3084 const MessageTemplate(MessageKind.EXPORT_BEFORE_PARTS,
3085 "Export declarations should come before parts.",
3086 howToFix: "Try moving this export further up in the file.",
3087 examples: const [
3088 const <String, String>{
3089 'main.dart': """
3090 library test.main;
3091 part 'part.dart';
3092 export 'dart:core';
3093 main() {}
3094 """,
3095 'part.dart': """
3096 part of test.main;
3097 """,
3098 }]),
3099
3100 //////////////////////////////////////////////////////////////////////////////
3101 // Patch errors start.
3102 //////////////////////////////////////////////////////////////////////////////
3103
3104 MessageKind.PATCH_RETURN_TYPE_MISMATCH:
3105 const MessageTemplate(MessageKind.PATCH_RETURN_TYPE_MISMATCH,
3106 "Patch return type '#{patchReturnType}' does not match "
3107 "'#{originReturnType}' on origin method '#{methodName}'."),
3108
3109 MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH:
3110 const MessageTemplate(
3111 MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH,
3112 "Required parameter count of patch method "
3113 "(#{patchParameterCount}) does not match parameter count on origin "
3114 "method '#{methodName}' (#{originParameterCount})."),
3115
3116 MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH:
3117 const MessageTemplate(
3118 MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH,
3119 "Optional parameter count of patch method "
3120 "(#{patchParameterCount}) does not match parameter count on origin "
3121 "method '#{methodName}' (#{originParameterCount})."),
3122
3123 MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH:
3124 const MessageTemplate(
3125 MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH,
3126 "Optional parameters of origin and patch method "
3127 "'#{methodName}' must both be either named or positional."),
3128
3129 MessageKind.PATCH_PARAMETER_MISMATCH:
3130 const MessageTemplate(MessageKind.PATCH_PARAMETER_MISMATCH,
3131 "Patch method parameter '#{patchParameter}' does not match "
3132 "'#{originParameter}' on origin method '#{methodName}'."),
3133
3134 MessageKind.PATCH_PARAMETER_TYPE_MISMATCH:
3135 const MessageTemplate(MessageKind.PATCH_PARAMETER_TYPE_MISMATCH,
3136 "Patch method parameter '#{parameterName}' type "
3137 "'#{patchParameterType}' does not match '#{originParameterType}' on "
3138 "origin method '#{methodName}'."),
3139
3140 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION:
3141 const MessageTemplate(MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION,
3142 "External method without an implementation."),
3143
3144 MessageKind.PATCH_POINT_TO_FUNCTION:
3145 const MessageTemplate(MessageKind.PATCH_POINT_TO_FUNCTION,
3146 "This is the function patch '#{functionName}'."),
3147
3148 MessageKind.PATCH_POINT_TO_CLASS:
3149 const MessageTemplate(MessageKind.PATCH_POINT_TO_CLASS,
3150 "This is the class patch '#{className}'."),
3151
3152 MessageKind.PATCH_POINT_TO_GETTER:
3153 const MessageTemplate(MessageKind.PATCH_POINT_TO_GETTER,
3154 "This is the getter patch '#{getterName}'."),
3155
3156 MessageKind.PATCH_POINT_TO_SETTER:
3157 const MessageTemplate(MessageKind.PATCH_POINT_TO_SETTER,
3158 "This is the setter patch '#{setterName}'."),
3159
3160 MessageKind.PATCH_POINT_TO_CONSTRUCTOR:
3161 const MessageTemplate(MessageKind.PATCH_POINT_TO_CONSTRUCTOR,
3162 "This is the constructor patch '#{constructorName}'."),
3163
3164 MessageKind.PATCH_POINT_TO_PARAMETER:
3165 const MessageTemplate(MessageKind.PATCH_POINT_TO_PARAMETER,
3166 "This is the patch parameter '#{parameterName}'."),
3167
3168 MessageKind.PATCH_NON_EXISTING:
3169 const MessageTemplate(MessageKind.PATCH_NON_EXISTING,
3170 "Origin does not exist for patch '#{name}'."),
3171
3172 // TODO(ahe): Eventually, this error should be removed as it will be
3173 // handled by the regular parser.
3174 MessageKind.PATCH_NONPATCHABLE:
3175 const MessageTemplate(MessageKind.PATCH_NONPATCHABLE,
3176 "Only classes and functions can be patched."),
3177
3178 MessageKind.PATCH_NON_EXTERNAL:
3179 const MessageTemplate(MessageKind.PATCH_NON_EXTERNAL,
3180 "Only external functions can be patched."),
3181
3182 MessageKind.PATCH_NON_CLASS:
3183 const MessageTemplate(MessageKind.PATCH_NON_CLASS,
3184 "Patching non-class with class patch '#{className}'."),
3185
3186 MessageKind.PATCH_NON_GETTER:
3187 const MessageTemplate(MessageKind.PATCH_NON_GETTER,
3188 "Cannot patch non-getter '#{name}' with getter patch."),
3189
3190 MessageKind.PATCH_NO_GETTER:
3191 const MessageTemplate(MessageKind.PATCH_NO_GETTER,
3192 "No getter found for getter patch '#{getterName}'."),
3193
3194 MessageKind.PATCH_NON_SETTER:
3195 const MessageTemplate(MessageKind.PATCH_NON_SETTER,
3196 "Cannot patch non-setter '#{name}' with setter patch."),
3197
3198 MessageKind.PATCH_NO_SETTER:
3199 const MessageTemplate(MessageKind.PATCH_NO_SETTER,
3200 "No setter found for setter patch '#{setterName}'."),
3201
3202 MessageKind.PATCH_NON_CONSTRUCTOR:
3203 const MessageTemplate(MessageKind.PATCH_NON_CONSTRUCTOR,
3204 "Cannot patch non-constructor with constructor patch "
3205 "'#{constructorName}'."),
3206
3207 MessageKind.PATCH_NON_FUNCTION:
3208 const MessageTemplate(MessageKind.PATCH_NON_FUNCTION,
3209 "Cannot patch non-function with function patch "
3210 "'#{functionName}'."),
3211
3212 MessageKind.EXTERNAL_WITH_BODY:
3213 const MessageTemplate(MessageKind.EXTERNAL_WITH_BODY,
3214 "External function '#{functionName}' cannot have a function body.",
3215 options: const ["--output-type=dart"],
3216 howToFix:
3217 "Try removing the 'external' modifier or the function body.",
3218 examples: const ["""
3219 external foo() => 0;
3220 main() => foo();
3221 """, """
3222 external foo() {}
3223 main() => foo();
3224 """]),
3225
3226 //////////////////////////////////////////////////////////////////////////////
3227 // Patch errors end.
3228 //////////////////////////////////////////////////////////////////////////////
3229
3230 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS:
3231 const MessageTemplate(MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, r'''
3232
3233 ****************************************************************
3234 * WARNING: dart:mirrors support in dart2js is experimental,
3235 * and not recommended.
3236 * This implementation of mirrors is incomplete,
3237 * and often greatly increases the size of the generated
3238 * JavaScript code.
3239 *
3240 * Your app imports dart:mirrors via:''''''
3241 $IMPORT_EXPERIMENTAL_MIRRORS_PADDING#{importChain}
3242 *
3243 * You can disable this message by using the --enable-experimental-mirrors
3244 * command-line flag.
3245 *
3246 * To learn what to do next, please visit:
3247 * http://dartlang.org/dart2js-reflection
3248 ****************************************************************
3249 '''),
3250
3251
3252 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND:
3253 const MessageTemplate(
3254 MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND,
3255 "dart:mirrors library is not supported when using this backend."),
3256
3257 MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS:
3258 const MessageTemplate(MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS,
3259 "Non-supported 'call' member on a native class, or a "
3260 "subclass of a native class."),
3261
3262 MessageKind.DIRECTLY_THROWING_NSM:
3263 const MessageTemplate(MessageKind.DIRECTLY_THROWING_NSM,
3264 "This 'noSuchMethod' implementation is guaranteed to throw an "
3265 "exception. The generated code will be smaller if it is "
3266 "rewritten.",
3267 howToFix: "Rewrite to "
3268 "'noSuchMethod(Invocation i) => super.noSuchMethod(i);'."),
3269
3270 MessageKind.COMPLEX_THROWING_NSM:
3271 const MessageTemplate(MessageKind.COMPLEX_THROWING_NSM,
3272 "This 'noSuchMethod' implementation is guaranteed to throw an "
3273 "exception. The generated code will be smaller and the compiler "
3274 "will be able to perform more optimizations if it is rewritten.",
3275 howToFix: "Rewrite to "
3276 "'noSuchMethod(Invocation i) => super.noSuchMethod(i);'."),
3277
3278 MessageKind.COMPLEX_RETURNING_NSM:
3279 const MessageTemplate(MessageKind.COMPLEX_RETURNING_NSM,
3280 "Overriding 'noSuchMethod' causes the compiler to generate "
3281 "more code and prevents the compiler from doing some optimizations.",
3282 howToFix: "Consider removing this 'noSuchMethod' implementation."),
3283
3284
3285 }; // End of TEMPLATES.
3286
3287 static const String IMPORT_EXPERIMENTAL_MIRRORS_PADDING = '\n* ';
3288
3289 toString() => template;
3290
3291 Message message([Map arguments = const {}, bool terse = false]) {
3292 return new Message(this, arguments, terse);
3293 }
3294
3295 bool get hasHowToFix => howToFix != null && howToFix != DONT_KNOW_HOW_TO_FIX;
3296 }
3297
3298 class Message {
3299 final MessageTemplate template;
3300 final Map arguments;
3301 final bool terse;
3302 String message;
3303
3304 Message(this.template, this.arguments, this.terse) {
3305 assert(() { computeMessage(); return true; });
3306 }
3307
3308 MessageKind get kind => template.kind;
3309
3310 String computeMessage() {
3311 if (message == null) {
3312 message = template.template;
3313 arguments.forEach((key, value) {
3314 message = message.replaceAll('#{${key}}', convertToString(value));
3315 });
3316 assert(invariant(
3317 CURRENT_ELEMENT_SPANNABLE,
3318 kind == MessageKind.GENERIC ||
3319 !message.contains(new RegExp(r'#\{.+\}')),
3320 message: 'Missing arguments in error message: "$message"'));
3321 if (!terse && template.hasHowToFix) {
3322 String howToFix = template.howToFix;
3323 arguments.forEach((key, value) {
3324 howToFix = howToFix.replaceAll('#{${key}}', convertToString(value));
3325 });
3326 message = '$message\n$howToFix';
3327 }
3328 }
3329 return message;
3330 }
3331
3332 String toString() {
3333 return computeMessage();
3334 }
3335
3336 bool operator==(other) {
3337 if (other is !Message) return false;
3338 return (template == other.template) && (toString() == other.toString());
3339 }
3340
3341 int get hashCode => throw new UnsupportedError('Message.hashCode');
3342
3343 static String convertToString(value) {
3344 if (value is ErrorToken) {
3345 // Shouldn't happen.
3346 return value.assertionMessage;
3347 } else if (value is Token) {
3348 value = value.value;
3349 }
3350 return '$value';
3351 }
3352 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/messages.dart ('k') | tests/compiler/dart2js/analyze_only_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698