OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart2js; | 5 part of dart2js; |
6 | 6 |
| 7 const DONT_KNOW_HOW_TO_FIX = ""; |
| 8 |
7 /** | 9 /** |
8 * The messages in this file should meet the following guide lines: | 10 * The messages in this file should meet the following guide lines: |
9 * | 11 * |
10 * 1. The message should start with exactly one of "Error", "Internal error", | 12 * 1. The message should start with exactly one of "Error", "Internal error", |
11 * "Warning", "Info", or "Hint" followed by a colon. It is crucial to users to | 13 * "Warning", "Info", or "Hint" followed by a colon. It is crucial to users to |
12 * be able to locate errors in the midst of warnings. | 14 * be able to locate errors in the midst of warnings. |
13 * TODO(ahe): Remove these prefixes from the error message. | 15 * TODO(ahe): Remove these prefixes from the error message. |
14 * | 16 * |
15 * 2. After the colon, one space and a complete sentence starting with an | 17 * 2. After the colon, one space and a complete sentence starting with an |
16 * uppercase letter, and ending with a period. | 18 * uppercase letter, and ending with a period. |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 | 535 |
534 static const DualKind CANNOT_RESOLVE_GETTER = const DualKind( | 536 static const DualKind CANNOT_RESOLVE_GETTER = const DualKind( |
535 error: const MessageKind('Error: Cannot resolve getter.'), | 537 error: const MessageKind('Error: Cannot resolve getter.'), |
536 warning: const MessageKind('Warning: Cannot resolve getter.')); | 538 warning: const MessageKind('Warning: Cannot resolve getter.')); |
537 | 539 |
538 static const DualKind CANNOT_RESOLVE_SETTER = const DualKind( | 540 static const DualKind CANNOT_RESOLVE_SETTER = const DualKind( |
539 error: const MessageKind('Error: Cannot resolve setter.'), | 541 error: const MessageKind('Error: Cannot resolve setter.'), |
540 warning: const MessageKind('Warning: Cannot resolve setter.')); | 542 warning: const MessageKind('Warning: Cannot resolve setter.')); |
541 | 543 |
542 static const MessageKind VOID_NOT_ALLOWED = const MessageKind( | 544 static const MessageKind VOID_NOT_ALLOWED = const MessageKind( |
543 'Error: Type "void" is only allowed in a return type.'); | 545 "Error: Type 'void' can't be used here because it isn't a return type.", |
| 546 howToFix: "Try removing 'void' keyword or replace it with 'var', 'final'," |
| 547 " or a type.", |
| 548 examples: const [ |
| 549 "void x; main() {}", |
| 550 "foo(void x) {} main() { foo(null); }", |
| 551 ]); |
544 | 552 |
545 static const MessageKind BEFORE_TOP_LEVEL = const MessageKind( | 553 static const MessageKind BEFORE_TOP_LEVEL = const MessageKind( |
546 'Error: Part header must come before top-level definitions.'); | 554 'Error: Part header must come before top-level definitions.'); |
547 | 555 |
548 static const MessageKind LIBRARY_NAME_MISMATCH = const MessageKind( | 556 static const MessageKind LIBRARY_NAME_MISMATCH = const MessageKind( |
549 'Warning: Expected part of library name "#{libraryName}".'); | 557 'Warning: Expected part of library name "#{libraryName}".'); |
550 | 558 |
551 static const MessageKind MISSING_PART_OF_TAG = const MessageKind( | 559 static const MessageKind MISSING_PART_OF_TAG = const MessageKind( |
552 'Error: This file has no part-of tag, but it is being used as a part.'); | 560 'Error: This file has no part-of tag, but it is being used as a part.'); |
553 | 561 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 """ | 755 """ |
748 // 'addAll' is misspelled. | 756 // 'addAll' is misspelled. |
749 @MirrorsUsed(targets: 'dart.core.List.addAl') | 757 @MirrorsUsed(targets: 'dart.core.List.addAl') |
750 import 'dart:mirrors'; | 758 import 'dart:mirrors'; |
751 | 759 |
752 main() {} | 760 main() {} |
753 """]); | 761 """]); |
754 | 762 |
755 static const MessageKind READ_SCRIPT_ERROR = const MessageKind( | 763 static const MessageKind READ_SCRIPT_ERROR = const MessageKind( |
756 "Error: Can't read '#{uri}' (#{exception}).", | 764 "Error: Can't read '#{uri}' (#{exception}).", |
| 765 // Don't know how to fix since the underlying error is unknown. |
| 766 howToFix: DONT_KNOW_HOW_TO_FIX, |
757 examples: const [ | 767 examples: const [ |
758 """ | 768 """ |
759 // 'foo.dart' does not exist. | 769 // 'foo.dart' does not exist. |
760 import 'foo.dart'; | 770 import 'foo.dart'; |
761 | 771 |
762 main() {} | 772 main() {} |
763 """]); | 773 """]); |
764 | 774 |
| 775 static const MessageKind EXTRANEOUS_MODIFIER = const MessageKind( |
| 776 "Error: Can't have modifier '#{modifier}' here.", |
| 777 howToFix: "Try removing '#{modifier}'.", |
| 778 examples: const [ |
| 779 "var String foo; main(){}", |
| 780 // "var get foo; main(){}", |
| 781 "var set foo; main(){}", |
| 782 "var final foo; main(){}", |
| 783 "var var foo; main(){}", |
| 784 "var const foo; main(){}", |
| 785 "var abstract foo; main(){}", |
| 786 "var static foo; main(){}", |
| 787 "var external foo; main(){}", |
| 788 "get var foo; main(){}", |
| 789 "set var foo; main(){}", |
| 790 "final var foo; main(){}", |
| 791 "var var foo; main(){}", |
| 792 "const var foo; main(){}", |
| 793 "abstract var foo; main(){}", |
| 794 "static var foo; main(){}", |
| 795 "external var foo; main(){}"]); |
| 796 |
| 797 static const MessageKind EXTRANEOUS_MODIFIER_REPLACE = const MessageKind( |
| 798 "Error: Can't have modifier '#{modifier}' here.", |
| 799 howToFix: "Try replacing modifier '#{modifier}' with 'var', 'final'," |
| 800 " or a type.", |
| 801 examples: const [ |
| 802 // "get foo; main(){}", |
| 803 "set foo; main(){}", |
| 804 "abstract foo; main(){}", |
| 805 "static foo; main(){}", |
| 806 "external foo; main(){}"]); |
| 807 |
| 808 static const MessageKind BODY_EXPECTED = const MessageKind( |
| 809 "Error: Expected a function body or '=>'.", |
| 810 // TODO(ahe): In some scenarios, we can suggest removing the 'static' |
| 811 // keyword. |
| 812 howToFix: "Try adding {}.", |
| 813 examples: const [ |
| 814 "main();"]); |
| 815 |
765 static const MessageKind COMPILER_CRASHED = const MessageKind( | 816 static const MessageKind COMPILER_CRASHED = const MessageKind( |
766 'Error: The compiler crashed when compiling this element.'); | 817 'Error: The compiler crashed when compiling this element.'); |
767 | 818 |
768 static const MessageKind PLEASE_REPORT_THE_CRASH = const MessageKind(''' | 819 static const MessageKind PLEASE_REPORT_THE_CRASH = const MessageKind(''' |
769 The compiler is broken. | 820 The compiler is broken. |
770 | 821 |
771 When compiling the above element, the compiler crashed. It is not | 822 When compiling the above element, the compiler crashed. It is not |
772 possible to tell if this is caused by a problem in your program or | 823 possible to tell if this is caused by a problem in your program or |
773 not. Regardless, the compiler should not crash. | 824 not. Regardless, the compiler should not crash. |
774 | 825 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 | 888 |
838 static const MessageKind PATCH_POINT_TO_CONSTRUCTOR = const MessageKind( | 889 static const MessageKind PATCH_POINT_TO_CONSTRUCTOR = const MessageKind( |
839 'Info: This is the constructor patch "#{constructorName}".'); | 890 'Info: This is the constructor patch "#{constructorName}".'); |
840 | 891 |
841 static const MessageKind PATCH_POINT_TO_PARAMETER = const MessageKind( | 892 static const MessageKind PATCH_POINT_TO_PARAMETER = const MessageKind( |
842 'Info: This is the patch parameter "#{parameterName}".'); | 893 'Info: This is the patch parameter "#{parameterName}".'); |
843 | 894 |
844 static const MessageKind PATCH_NON_EXISTING = const MessageKind( | 895 static const MessageKind PATCH_NON_EXISTING = const MessageKind( |
845 'Error: Origin does not exist for patch "#{name}".'); | 896 'Error: Origin does not exist for patch "#{name}".'); |
846 | 897 |
| 898 // TODO(ahe): Eventually, this error should be removed as it will be handled |
| 899 // by the regular parser. |
847 static const MessageKind PATCH_NONPATCHABLE = const MessageKind( | 900 static const MessageKind PATCH_NONPATCHABLE = const MessageKind( |
848 'Error: Only classes and functions can be patched.'); | 901 'Error: Only classes and functions can be patched.'); |
849 | 902 |
850 static const MessageKind PATCH_NON_EXTERNAL = const MessageKind( | 903 static const MessageKind PATCH_NON_EXTERNAL = const MessageKind( |
851 'Error: Only external functions can be patched.'); | 904 'Error: Only external functions can be patched.'); |
852 | 905 |
853 static const MessageKind PATCH_NON_CLASS = const MessageKind( | 906 static const MessageKind PATCH_NON_CLASS = const MessageKind( |
854 'Error: Patching non-class with class patch "#{className}".'); | 907 'Error: Patching non-class with class patch "#{className}".'); |
855 | 908 |
856 static const MessageKind PATCH_NON_GETTER = const MessageKind( | 909 static const MessageKind PATCH_NON_GETTER = const MessageKind( |
(...skipping 22 matching lines...) Expand all Loading... |
879 | 932 |
880 toString() => template; | 933 toString() => template; |
881 | 934 |
882 Message message([Map arguments = const {}, bool terse = false]) { | 935 Message message([Map arguments = const {}, bool terse = false]) { |
883 return new Message(this, arguments, terse); | 936 return new Message(this, arguments, terse); |
884 } | 937 } |
885 | 938 |
886 CompilationError error([Map arguments = const {}, bool terse = false]) { | 939 CompilationError error([Map arguments = const {}, bool terse = false]) { |
887 return new CompilationError(this, arguments, terse); | 940 return new CompilationError(this, arguments, terse); |
888 } | 941 } |
| 942 |
| 943 bool get hasHowToFix => howToFix != null && howToFix != DONT_KNOW_HOW_TO_FIX; |
889 } | 944 } |
890 | 945 |
891 class DualKind { | 946 class DualKind { |
892 final MessageKind error; | 947 final MessageKind error; |
893 final MessageKind warning; | 948 final MessageKind warning; |
894 | 949 |
895 const DualKind({this.error, this.warning}); | 950 const DualKind({this.error, this.warning}); |
896 } | 951 } |
897 | 952 |
898 class Message { | 953 class Message { |
(...skipping 10 matching lines...) Expand all Loading... |
909 if (message == null) { | 964 if (message == null) { |
910 message = kind.template; | 965 message = kind.template; |
911 arguments.forEach((key, value) { | 966 arguments.forEach((key, value) { |
912 String string = slowToString(value); | 967 String string = slowToString(value); |
913 message = message.replaceAll('#{${key}}', string); | 968 message = message.replaceAll('#{${key}}', string); |
914 }); | 969 }); |
915 assert(invariant( | 970 assert(invariant( |
916 CURRENT_ELEMENT_SPANNABLE, | 971 CURRENT_ELEMENT_SPANNABLE, |
917 !message.contains(new RegExp(r'#\{.+\}')), | 972 !message.contains(new RegExp(r'#\{.+\}')), |
918 message: 'Missing arguments in error message: "$message"')); | 973 message: 'Missing arguments in error message: "$message"')); |
919 if (!terse && kind.howToFix != null) { | 974 if (!terse && kind.hasHowToFix) { |
920 String howToFix = kind.howToFix; | 975 String howToFix = kind.howToFix; |
921 arguments.forEach((key, value) { | 976 arguments.forEach((key, value) { |
922 String string = slowToString(value); | 977 String string = slowToString(value); |
923 howToFix = howToFix.replaceAll('#{${key}}', string); | 978 howToFix = howToFix.replaceAll('#{${key}}', string); |
924 }); | 979 }); |
925 message = '$message\n$howToFix'; | 980 message = '$message\n$howToFix'; |
926 } | 981 } |
927 } | 982 } |
928 return message; | 983 return message; |
929 } | 984 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 | 1022 |
968 class CompileTimeConstantError extends Diagnostic { | 1023 class CompileTimeConstantError extends Diagnostic { |
969 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse) | 1024 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse) |
970 : super(kind, arguments, terse); | 1025 : super(kind, arguments, terse); |
971 } | 1026 } |
972 | 1027 |
973 class CompilationError extends Diagnostic { | 1028 class CompilationError extends Diagnostic { |
974 CompilationError(MessageKind kind, Map arguments, bool terse) | 1029 CompilationError(MessageKind kind, Map arguments, bool terse) |
975 : super(kind, arguments, terse); | 1030 : super(kind, arguments, terse); |
976 } | 1031 } |
OLD | NEW |