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.compile_time_error_code_test; | 5 library engine.compile_time_error_code_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
8 import 'package:analyzer/src/generated/error.dart'; | 8 import 'package:analyzer/src/generated/error.dart'; |
9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
10 import 'package:analyzer/src/generated/source_io.dart'; | 10 import 'package:analyzer/src/generated/source_io.dart'; |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 _check_constEvalThrowsException_binary_null("5 + null", true); | 1033 _check_constEvalThrowsException_binary_null("5 + null", true); |
1034 } | 1034 } |
1035 | 1035 |
1036 void test_constEvalThrowsException_divisionByZero() { | 1036 void test_constEvalThrowsException_divisionByZero() { |
1037 Source source = addSource("const C = 1 ~/ 0;"); | 1037 Source source = addSource("const C = 1 ~/ 0;"); |
1038 computeLibrarySourceErrors(source); | 1038 computeLibrarySourceErrors(source); |
1039 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE]); | 1039 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE]); |
1040 verify([source]); | 1040 verify([source]); |
1041 } | 1041 } |
1042 | 1042 |
| 1043 void test_constEvalThrowsException_finalAlreadySet_initializer() { |
| 1044 // If a final variable has an initializer at the site of its declaration, |
| 1045 // and at the site of the constructor, then invoking that constructor would |
| 1046 // produce a runtime error; hence invoking that constructor via the "const" |
| 1047 // keyword results in a compile-time error. |
| 1048 Source source = addSource(''' |
| 1049 class C { |
| 1050 final x = 1; |
| 1051 const C() : x = 2; |
| 1052 } |
| 1053 var x = const C(); |
| 1054 '''); |
| 1055 computeLibrarySourceErrors(source); |
| 1056 assertErrors(source, [ |
| 1057 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
| 1058 StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION |
| 1059 ]); |
| 1060 verify([source]); |
| 1061 } |
| 1062 |
| 1063 void test_constEvalThrowsException_finalAlreadySet_initializing_formal() { |
| 1064 // If a final variable has an initializer at the site of its declaration, |
| 1065 // and it is initialized using an initializing formal at the site of the |
| 1066 // constructor, then invoking that constructor would produce a runtime |
| 1067 // error; hence invoking that constructor via the "const" keyword results |
| 1068 // in a compile-time error. |
| 1069 Source source = addSource(''' |
| 1070 class C { |
| 1071 final x = 1; |
| 1072 const C(this.x); |
| 1073 } |
| 1074 var x = const C(2); |
| 1075 '''); |
| 1076 computeLibrarySourceErrors(source); |
| 1077 assertErrors(source, [ |
| 1078 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
| 1079 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR |
| 1080 ]); |
| 1081 verify([source]); |
| 1082 } |
| 1083 |
1043 void test_constEvalThrowsException_unaryBitNot_null() { | 1084 void test_constEvalThrowsException_unaryBitNot_null() { |
1044 Source source = addSource("const C = ~null;"); | 1085 Source source = addSource("const C = ~null;"); |
1045 computeLibrarySourceErrors(source); | 1086 computeLibrarySourceErrors(source); |
1046 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 1087 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
1047 // no verify(), '~null' is not resolved | 1088 // no verify(), '~null' is not resolved |
1048 } | 1089 } |
1049 | 1090 |
1050 void test_constEvalThrowsException_unaryNegated_null() { | 1091 void test_constEvalThrowsException_unaryNegated_null() { |
1051 Source source = addSource("const C = -null;"); | 1092 Source source = addSource("const C = -null;"); |
1052 computeLibrarySourceErrors(source); | 1093 computeLibrarySourceErrors(source); |
(...skipping 4851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5904 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 5945 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
5905 verify([source]); | 5946 verify([source]); |
5906 reset(); | 5947 reset(); |
5907 } | 5948 } |
5908 | 5949 |
5909 void _check_wrongNumberOfParametersForOperator1(String name) { | 5950 void _check_wrongNumberOfParametersForOperator1(String name) { |
5910 _check_wrongNumberOfParametersForOperator(name, ""); | 5951 _check_wrongNumberOfParametersForOperator(name, ""); |
5911 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 5952 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
5912 } | 5953 } |
5913 } | 5954 } |
OLD | NEW |