OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library engine.error; | 5 library engine.error; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'ast.dart' show AstNode; | 9 import 'ast.dart' show AstNode; |
10 import 'element.dart'; | 10 import 'element.dart'; |
(...skipping 10 matching lines...) Expand all Loading... |
21 /** | 21 /** |
22 * An empty array of errors used when no errors are expected. | 22 * An empty array of errors used when no errors are expected. |
23 */ | 23 */ |
24 static const List<AnalysisError> NO_ERRORS = const <AnalysisError>[]; | 24 static const List<AnalysisError> NO_ERRORS = const <AnalysisError>[]; |
25 | 25 |
26 /** | 26 /** |
27 * A [Comparator] that sorts by the name of the file that the [AnalysisError] | 27 * A [Comparator] that sorts by the name of the file that the [AnalysisError] |
28 * was found. | 28 * was found. |
29 */ | 29 */ |
30 static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, | 30 static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, |
31 AnalysisError o2) => o1.source.shortName.compareTo(o2.source.shortName); | 31 AnalysisError o2) => |
| 32 o1.source.shortName.compareTo(o2.source.shortName); |
32 | 33 |
33 /** | 34 /** |
34 * A [Comparator] that sorts error codes first by their severity (errors | 35 * A [Comparator] that sorts error codes first by their severity (errors |
35 * first, warnings second), and then by the the error code type. | 36 * first, warnings second), and then by the the error code type. |
36 */ | 37 */ |
37 static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = (AnalysisError o1, | 38 static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = |
38 AnalysisError o2) { | 39 (AnalysisError o1, AnalysisError o2) { |
39 ErrorCode errorCode1 = o1.errorCode; | 40 ErrorCode errorCode1 = o1.errorCode; |
40 ErrorCode errorCode2 = o2.errorCode; | 41 ErrorCode errorCode2 = o2.errorCode; |
41 ErrorSeverity errorSeverity1 = errorCode1.errorSeverity; | 42 ErrorSeverity errorSeverity1 = errorCode1.errorSeverity; |
42 ErrorSeverity errorSeverity2 = errorCode2.errorSeverity; | 43 ErrorSeverity errorSeverity2 = errorCode2.errorSeverity; |
43 if (errorSeverity1 == errorSeverity2) { | 44 if (errorSeverity1 == errorSeverity2) { |
44 ErrorType errorType1 = errorCode1.type; | 45 ErrorType errorType1 = errorCode1.type; |
45 ErrorType errorType2 = errorCode2.type; | 46 ErrorType errorType2 = errorCode2.type; |
46 return errorType1.compareTo(errorType2); | 47 return errorType1.compareTo(errorType2); |
47 } else { | 48 } else { |
48 return errorSeverity2.compareTo(errorSeverity1); | 49 return errorSeverity2.compareTo(errorSeverity1); |
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 * Parameters: | 1031 * Parameters: |
1031 * 0: the name of the type that cannot be extended | 1032 * 0: the name of the type that cannot be extended |
1032 * | 1033 * |
1033 * See [IMPLEMENTS_DEFERRED_CLASS], and [MIXIN_DEFERRED_CLASS]. | 1034 * See [IMPLEMENTS_DEFERRED_CLASS], and [MIXIN_DEFERRED_CLASS]. |
1034 */ | 1035 */ |
1035 static const CompileTimeErrorCode EXTENDS_DEFERRED_CLASS = | 1036 static const CompileTimeErrorCode EXTENDS_DEFERRED_CLASS = |
1036 const CompileTimeErrorCode('EXTENDS_DEFERRED_CLASS', | 1037 const CompileTimeErrorCode('EXTENDS_DEFERRED_CLASS', |
1037 "This class cannot extend the deferred class '{0}'"); | 1038 "This class cannot extend the deferred class '{0}'"); |
1038 | 1039 |
1039 /** | 1040 /** |
| 1041 * DEP 37 extends the syntax for assert() to allow a second "message" |
| 1042 * argument. We issue this error if the user tries to supply a "message" |
| 1043 * argument but the DEP is not enabled. |
| 1044 */ |
| 1045 static const CompileTimeErrorCode EXTRA_ARGUMENT_TO_ASSERT = |
| 1046 const CompileTimeErrorCode('EXTRA_ARGUMENT_TO_ASSERT', |
| 1047 "Assertions only accept a single argument"); |
| 1048 |
| 1049 /** |
1040 * 12.14.2 Binding Actuals to Formals: It is a static warning if <i>m < | 1050 * 12.14.2 Binding Actuals to Formals: It is a static warning if <i>m < |
1041 * h</i> or if <i>m > n</i>. | 1051 * h</i> or if <i>m > n</i>. |
1042 * | 1052 * |
1043 * 12.11.2 Const: It is a compile-time error if evaluation of a constant | 1053 * 12.11.2 Const: It is a compile-time error if evaluation of a constant |
1044 * object results in an uncaught exception being thrown. | 1054 * object results in an uncaught exception being thrown. |
1045 * | 1055 * |
1046 * Parameters: | 1056 * Parameters: |
1047 * 0: the maximum number of positional arguments | 1057 * 0: the maximum number of positional arguments |
1048 * 1: the actual number of positional arguments given | 1058 * 1: the actual number of positional arguments given |
1049 */ | 1059 */ |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 * * The static type of <i>e</i> is an enumerated typed with elements | 1563 * * The static type of <i>e</i> is an enumerated typed with elements |
1554 * <i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>. | 1564 * <i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>. |
1555 * * The sets {<i>e<sub>1</sub></i>, …, <i>e<sub>k</sub></i>} and | 1565 * * The sets {<i>e<sub>1</sub></i>, …, <i>e<sub>k</sub></i>} and |
1556 * {<i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>} are not the | 1566 * {<i>id<sub>1</sub></i>, …, <i>id<sub>n</sub></i>} are not the |
1557 * same. | 1567 * same. |
1558 * | 1568 * |
1559 * Parameters: | 1569 * Parameters: |
1560 * 0: the name of the constant that is missing | 1570 * 0: the name of the constant that is missing |
1561 */ | 1571 */ |
1562 static const CompileTimeErrorCode MISSING_ENUM_CONSTANT_IN_SWITCH = | 1572 static const CompileTimeErrorCode MISSING_ENUM_CONSTANT_IN_SWITCH = |
1563 const CompileTimeErrorCode('MISSING_ENUM_CONSTANT_IN_SWITCH', | 1573 const CompileTimeErrorCode( |
| 1574 'MISSING_ENUM_CONSTANT_IN_SWITCH', |
1564 "Missing case clause for '{0}'", | 1575 "Missing case clause for '{0}'", |
1565 "Add a case clause for the missing constant or add a default clause.")
; | 1576 "Add a case clause for the missing constant or add a default clause.")
; |
1566 | 1577 |
1567 /** | 1578 /** |
1568 * 9 Mixins: It is a compile-time error if a declared or derived mixin | 1579 * 9 Mixins: It is a compile-time error if a declared or derived mixin |
1569 * explicitly declares a constructor. | 1580 * explicitly declares a constructor. |
1570 * | 1581 * |
1571 * Parameters: | 1582 * Parameters: |
1572 * 0: the name of the mixin that is invalid | 1583 * 0: the name of the mixin that is invalid |
1573 */ | 1584 */ |
(...skipping 15 matching lines...) Expand all Loading... |
1589 "This class cannot mixin the deferred class '{0}'"); | 1600 "This class cannot mixin the deferred class '{0}'"); |
1590 | 1601 |
1591 /** | 1602 /** |
1592 * Not yet in the spec, but consistent with VM behavior. It is a | 1603 * Not yet in the spec, but consistent with VM behavior. It is a |
1593 * compile-time error if all of the constructors of a mixin's base class have | 1604 * compile-time error if all of the constructors of a mixin's base class have |
1594 * at least one optional parameter (since only constructors that lack | 1605 * at least one optional parameter (since only constructors that lack |
1595 * optional parameters can be forwarded to the mixin). See | 1606 * optional parameters can be forwarded to the mixin). See |
1596 * https://code.google.com/p/dart/issues/detail?id=15101#c4 | 1607 * https://code.google.com/p/dart/issues/detail?id=15101#c4 |
1597 */ | 1608 */ |
1598 static const CompileTimeErrorCode MIXIN_HAS_NO_CONSTRUCTORS = | 1609 static const CompileTimeErrorCode MIXIN_HAS_NO_CONSTRUCTORS = |
1599 const CompileTimeErrorCode('MIXIN_HAS_NO_CONSTRUCTORS', | 1610 const CompileTimeErrorCode( |
| 1611 'MIXIN_HAS_NO_CONSTRUCTORS', |
1600 "This mixin application is invalid because all of the constructors " | 1612 "This mixin application is invalid because all of the constructors " |
1601 "in the base class '{0}' have optional parameters."); | 1613 "in the base class '{0}' have optional parameters."); |
1602 | 1614 |
1603 /** | 1615 /** |
1604 * 9 Mixins: It is a compile-time error if a mixin is derived from a class | 1616 * 9 Mixins: It is a compile-time error if a mixin is derived from a class |
1605 * whose superclass is not Object. | 1617 * whose superclass is not Object. |
1606 * | 1618 * |
1607 * Parameters: | 1619 * Parameters: |
1608 * 0: the name of the mixin that is invalid | 1620 * 0: the name of the mixin that is invalid |
1609 */ | 1621 */ |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2878 | 2890 |
2879 /** | 2891 /** |
2880 * Generate a hint for methods or functions that have a return type, but do | 2892 * Generate a hint for methods or functions that have a return type, but do |
2881 * not have a non-void return statement on all branches. At the end of methods | 2893 * not have a non-void return statement on all branches. At the end of methods |
2882 * or functions with no return, Dart implicitly returns `null`, avoiding these | 2894 * or functions with no return, Dart implicitly returns `null`, avoiding these |
2883 * implicit returns is considered a best practice. | 2895 * implicit returns is considered a best practice. |
2884 * | 2896 * |
2885 * Parameters: | 2897 * Parameters: |
2886 * 0: the name of the declared return type | 2898 * 0: the name of the declared return type |
2887 */ | 2899 */ |
2888 static const HintCode MISSING_RETURN = const HintCode('MISSING_RETURN', | 2900 static const HintCode MISSING_RETURN = const HintCode( |
| 2901 'MISSING_RETURN', |
2889 "This function declares a return type of '{0}', but does not end with a re
turn statement", | 2902 "This function declares a return type of '{0}', but does not end with a re
turn statement", |
2890 "Either add a return statement or change the return type to 'void'"); | 2903 "Either add a return statement or change the return type to 'void'"); |
2891 | 2904 |
2892 /** | 2905 /** |
2893 * A getter with the override annotation does not override an existing getter. | 2906 * A getter with the override annotation does not override an existing getter. |
2894 */ | 2907 */ |
2895 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode( | 2908 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode( |
2896 'OVERRIDE_ON_NON_OVERRIDING_GETTER', | 2909 'OVERRIDE_ON_NON_OVERRIDING_GETTER', |
2897 "Getter does not override an inherited getter"); | 2910 "Getter does not override an inherited getter"); |
2898 | 2911 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3196 } | 3209 } |
3197 | 3210 |
3198 /** | 3211 /** |
3199 * The error codes used for static type warnings. The convention for this class | 3212 * The error codes used for static type warnings. The convention for this class |
3200 * is for the name of the error code to indicate the problem that caused the | 3213 * is for the name of the error code to indicate the problem that caused the |
3201 * error to be generated and for the error message to explain what is wrong and, | 3214 * error to be generated and for the error message to explain what is wrong and, |
3202 * when appropriate, how the problem can be corrected. | 3215 * when appropriate, how the problem can be corrected. |
3203 */ | 3216 */ |
3204 class StaticTypeWarningCode extends ErrorCode { | 3217 class StaticTypeWarningCode extends ErrorCode { |
3205 /** | 3218 /** |
| 3219 * 17.17 Assert: It is a static type warning if the type of s may not be |
| 3220 * assigned to String. |
| 3221 */ |
| 3222 static const StaticTypeWarningCode ASSERT_MESSAGE_NON_STRING = |
| 3223 const StaticTypeWarningCode('ASSERT_MESSAGE_NON_STRING', |
| 3224 "Assertion messages must be assignable to String"); |
| 3225 |
| 3226 /** |
3206 * 12.7 Lists: A fresh instance (7.6.1) <i>a</i>, of size <i>n</i>, whose | 3227 * 12.7 Lists: A fresh instance (7.6.1) <i>a</i>, of size <i>n</i>, whose |
3207 * class implements the built-in class <i>List<E></i> is allocated. | 3228 * class implements the built-in class <i>List<E></i> is allocated. |
3208 * | 3229 * |
3209 * Parameters: | 3230 * Parameters: |
3210 * 0: the number of provided type arguments | 3231 * 0: the number of provided type arguments |
3211 */ | 3232 */ |
3212 static const StaticTypeWarningCode EXPECTED_ONE_LIST_TYPE_ARGUMENTS = | 3233 static const StaticTypeWarningCode EXPECTED_ONE_LIST_TYPE_ARGUMENTS = |
3213 const StaticTypeWarningCode('EXPECTED_ONE_LIST_TYPE_ARGUMENTS', | 3234 const StaticTypeWarningCode('EXPECTED_ONE_LIST_TYPE_ARGUMENTS', |
3214 "List literal requires exactly one type arguments or none, but {0} fou
nd"); | 3235 "List literal requires exactly one type arguments or none, but {0} fou
nd"); |
3215 | 3236 |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3721 * 2. If <i>N</i> is referenced as a function, getter or setter, a | 3742 * 2. If <i>N</i> is referenced as a function, getter or setter, a |
3722 * <i>NoSuchMethodError</i> is raised. | 3743 * <i>NoSuchMethodError</i> is raised. |
3723 * 3. If <i>N</i> is referenced as a type, it is treated as a malformed type. | 3744 * 3. If <i>N</i> is referenced as a type, it is treated as a malformed type. |
3724 * | 3745 * |
3725 * Parameters: | 3746 * Parameters: |
3726 * 0: the name of the ambiguous type | 3747 * 0: the name of the ambiguous type |
3727 * 1: the name of the first library that the type is found | 3748 * 1: the name of the first library that the type is found |
3728 * 2: the name of the second library that the type is found | 3749 * 2: the name of the second library that the type is found |
3729 */ | 3750 */ |
3730 static const StaticWarningCode AMBIGUOUS_IMPORT = const StaticWarningCode( | 3751 static const StaticWarningCode AMBIGUOUS_IMPORT = const StaticWarningCode( |
3731 'AMBIGUOUS_IMPORT', "The name '{0}' is defined in the libraries {1}", | 3752 'AMBIGUOUS_IMPORT', |
| 3753 "The name '{0}' is defined in the libraries {1}", |
3732 "Consider using 'as prefix' for one of the import directives " | 3754 "Consider using 'as prefix' for one of the import directives " |
3733 "or hiding the name from all but one of the imports."); | 3755 "or hiding the name from all but one of the imports."); |
3734 | 3756 |
3735 /** | 3757 /** |
3736 * 12.11.1 New: It is a static warning if the static type of <i>a<sub>i</sub>, | 3758 * 12.11.1 New: It is a static warning if the static type of <i>a<sub>i</sub>, |
3737 * 1 <= i <= n+ k</i> may not be assigned to the type of the | 3759 * 1 <= i <= n+ k</i> may not be assigned to the type of the |
3738 * corresponding formal parameter of the constructor <i>T.id</i> (respectively | 3760 * corresponding formal parameter of the constructor <i>T.id</i> (respectively |
3739 * <i>T</i>). | 3761 * <i>T</i>). |
3740 * | 3762 * |
3741 * 12.11.2 Const: It is a static warning if the static type of | 3763 * 12.11.2 Const: It is a static warning if the static type of |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4938 * Initialize a newly created error code to have the given [name]. | 4960 * Initialize a newly created error code to have the given [name]. |
4939 */ | 4961 */ |
4940 const TodoCode(String name) : super(name, "{0}"); | 4962 const TodoCode(String name) : super(name, "{0}"); |
4941 | 4963 |
4942 @override | 4964 @override |
4943 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | 4965 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; |
4944 | 4966 |
4945 @override | 4967 @override |
4946 ErrorType get type => ErrorType.TODO; | 4968 ErrorType get type => ErrorType.TODO; |
4947 } | 4969 } |
OLD | NEW |