| 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/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:unittest/unittest.dart' as _ut; | 10 import 'package:unittest/unittest.dart' as _ut; |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 Source source = addSource("class as {}"); | 629 Source source = addSource("class as {}"); |
| 630 resolve(source); | 630 resolve(source); |
| 631 assertErrors( | 631 assertErrors( |
| 632 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]); | 632 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]); |
| 633 verify([source]); | 633 verify([source]); |
| 634 } | 634 } |
| 635 | 635 |
| 636 void test_builtInIdentifierAsTypeParameterName() { | 636 void test_builtInIdentifierAsTypeParameterName() { |
| 637 Source source = addSource("class A<as> {}"); | 637 Source source = addSource("class A<as> {}"); |
| 638 resolve(source); | 638 resolve(source); |
| 639 assertErrors(source, [ | 639 assertErrors(source, |
| 640 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME | 640 [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME]); |
| 641 ]); | |
| 642 verify([source]); | 641 verify([source]); |
| 643 } | 642 } |
| 644 | 643 |
| 645 void test_caseExpressionTypeImplementsEquals() { | 644 void test_caseExpressionTypeImplementsEquals() { |
| 646 Source source = addSource(r''' | 645 Source source = addSource(r''' |
| 647 class IntWrapper { | 646 class IntWrapper { |
| 648 final int value; | 647 final int value; |
| 649 const IntWrapper(this.value); | 648 const IntWrapper(this.value); |
| 650 bool operator ==(IntWrapper x) { | 649 bool operator ==(IntWrapper x) { |
| 651 return value == x.value; | 650 return value == x.value; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 ], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); | 976 ], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); |
| 978 } | 977 } |
| 979 | 978 |
| 980 void test_constEval_newInstance_constConstructor() { | 979 void test_constEval_newInstance_constConstructor() { |
| 981 Source source = addSource(r''' | 980 Source source = addSource(r''' |
| 982 class A { | 981 class A { |
| 983 const A(); | 982 const A(); |
| 984 } | 983 } |
| 985 const a = new A();'''); | 984 const a = new A();'''); |
| 986 resolve(source); | 985 resolve(source); |
| 987 assertErrors(source, [ | 986 assertErrors(source, |
| 988 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 987 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 989 ]); | |
| 990 verify([source]); | 988 verify([source]); |
| 991 } | 989 } |
| 992 | 990 |
| 993 void test_constEval_newInstance_externalFactoryConstConstructor() { | 991 void test_constEval_newInstance_externalFactoryConstConstructor() { |
| 994 // We can't evaluate "const A()" because its constructor is external. But | 992 // We can't evaluate "const A()" because its constructor is external. But |
| 995 // the code is correct--we shouldn't report an error. | 993 // the code is correct--we shouldn't report an error. |
| 996 Source source = addSource(r''' | 994 Source source = addSource(r''' |
| 997 class A { | 995 class A { |
| 998 external factory const A(); | 996 external factory const A(); |
| 999 } | 997 } |
| 1000 const x = const A();'''); | 998 const x = const A();'''); |
| 1001 resolve(source); | 999 resolve(source); |
| 1002 assertNoErrors(source); | 1000 assertNoErrors(source); |
| 1003 verify([source]); | 1001 verify([source]); |
| 1004 } | 1002 } |
| 1005 | 1003 |
| 1006 void test_constEval_propertyExtraction_targetNotConst() { | 1004 void test_constEval_propertyExtraction_targetNotConst() { |
| 1007 Source source = addSource(r''' | 1005 Source source = addSource(r''' |
| 1008 class A { | 1006 class A { |
| 1009 const A(); | 1007 const A(); |
| 1010 m() {} | 1008 m() {} |
| 1011 } | 1009 } |
| 1012 final a = const A(); | 1010 final a = const A(); |
| 1013 const C = a.m;'''); | 1011 const C = a.m;'''); |
| 1014 resolve(source); | 1012 resolve(source); |
| 1015 assertErrors(source, [ | 1013 assertErrors(source, |
| 1016 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 1014 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 1017 ]); | |
| 1018 verify([source]); | 1015 verify([source]); |
| 1019 } | 1016 } |
| 1020 | 1017 |
| 1021 void test_constEvalThrowsException_binaryMinus_null() { | 1018 void test_constEvalThrowsException_binaryMinus_null() { |
| 1022 _check_constEvalThrowsException_binary_null("null - 5", false); | 1019 _check_constEvalThrowsException_binary_null("null - 5", false); |
| 1023 _check_constEvalThrowsException_binary_null("5 - null", true); | 1020 _check_constEvalThrowsException_binary_null("5 - null", true); |
| 1024 } | 1021 } |
| 1025 | 1022 |
| 1026 void test_constEvalThrowsException_binaryPlus_null() { | 1023 void test_constEvalThrowsException_binaryPlus_null() { |
| 1027 _check_constEvalThrowsException_binary_null("null + 5", false); | 1024 _check_constEvalThrowsException_binary_null("null + 5", false); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); | 1137 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); |
| 1141 verify([source]); | 1138 verify([source]); |
| 1142 } | 1139 } |
| 1143 | 1140 |
| 1144 void test_constInitializedWithNonConstValue() { | 1141 void test_constInitializedWithNonConstValue() { |
| 1145 Source source = addSource(r''' | 1142 Source source = addSource(r''' |
| 1146 f(p) { | 1143 f(p) { |
| 1147 const C = p; | 1144 const C = p; |
| 1148 }'''); | 1145 }'''); |
| 1149 resolve(source); | 1146 resolve(source); |
| 1150 assertErrors(source, [ | 1147 assertErrors(source, |
| 1151 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 1148 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 1152 ]); | |
| 1153 verify([source]); | 1149 verify([source]); |
| 1154 } | 1150 } |
| 1155 | 1151 |
| 1156 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { | 1152 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { |
| 1157 Source source = addSource("const List L = [0];"); | 1153 Source source = addSource("const List L = [0];"); |
| 1158 resolve(source); | 1154 resolve(source); |
| 1159 assertErrors(source, [ | 1155 assertErrors(source, |
| 1160 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 1156 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 1161 ]); | |
| 1162 verify([source]); | 1157 verify([source]); |
| 1163 } | 1158 } |
| 1164 | 1159 |
| 1165 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { | 1160 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { |
| 1166 Source source = addSource("const Map M = {'a' : 0};"); | 1161 Source source = addSource("const Map M = {'a' : 0};"); |
| 1167 resolve(source); | 1162 resolve(source); |
| 1168 assertErrors(source, [ | 1163 assertErrors(source, |
| 1169 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 1164 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 1170 ]); | |
| 1171 verify([source]); | 1165 verify([source]); |
| 1172 } | 1166 } |
| 1173 | 1167 |
| 1174 void test_constInitializedWithNonConstValueFromDeferredClass() { | 1168 void test_constInitializedWithNonConstValueFromDeferredClass() { |
| 1175 resolveWithErrors(<String>[ | 1169 resolveWithErrors(<String>[ |
| 1176 r''' | 1170 r''' |
| 1177 library lib1; | 1171 library lib1; |
| 1178 const V = 1;''', | 1172 const V = 1;''', |
| 1179 r''' | 1173 r''' |
| 1180 library root; | 1174 library root; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 void test_constMapKeyTypeImplementsEquals_direct() { | 1206 void test_constMapKeyTypeImplementsEquals_direct() { |
| 1213 Source source = addSource(r''' | 1207 Source source = addSource(r''' |
| 1214 class A { | 1208 class A { |
| 1215 const A(); | 1209 const A(); |
| 1216 operator ==(other) => false; | 1210 operator ==(other) => false; |
| 1217 } | 1211 } |
| 1218 main() { | 1212 main() { |
| 1219 const {const A() : 0}; | 1213 const {const A() : 0}; |
| 1220 }'''); | 1214 }'''); |
| 1221 resolve(source); | 1215 resolve(source); |
| 1222 assertErrors(source, [ | 1216 assertErrors(source, |
| 1223 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS | 1217 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
| 1224 ]); | |
| 1225 verify([source]); | 1218 verify([source]); |
| 1226 } | 1219 } |
| 1227 | 1220 |
| 1228 void test_constMapKeyTypeImplementsEquals_dynamic() { | 1221 void test_constMapKeyTypeImplementsEquals_dynamic() { |
| 1229 // Note: static type of B.a is "dynamic", but actual type of the const | 1222 // Note: static type of B.a is "dynamic", but actual type of the const |
| 1230 // object is A. We need to make sure we examine the actual type when | 1223 // object is A. We need to make sure we examine the actual type when |
| 1231 // deciding whether there is a problem with operator==. | 1224 // deciding whether there is a problem with operator==. |
| 1232 Source source = addSource(r''' | 1225 Source source = addSource(r''' |
| 1233 class A { | 1226 class A { |
| 1234 const A(); | 1227 const A(); |
| 1235 operator ==(other) => false; | 1228 operator ==(other) => false; |
| 1236 } | 1229 } |
| 1237 class B { | 1230 class B { |
| 1238 static const a = const A(); | 1231 static const a = const A(); |
| 1239 } | 1232 } |
| 1240 main() { | 1233 main() { |
| 1241 const {B.a : 0}; | 1234 const {B.a : 0}; |
| 1242 }'''); | 1235 }'''); |
| 1243 resolve(source); | 1236 resolve(source); |
| 1244 assertErrors(source, [ | 1237 assertErrors(source, |
| 1245 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS | 1238 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
| 1246 ]); | |
| 1247 verify([source]); | 1239 verify([source]); |
| 1248 } | 1240 } |
| 1249 | 1241 |
| 1250 void test_constMapKeyTypeImplementsEquals_factory() { | 1242 void test_constMapKeyTypeImplementsEquals_factory() { |
| 1251 Source source = addSource(r''' | 1243 Source source = addSource(r''' |
| 1252 class A { const factory A() = B; } | 1244 class A { const factory A() = B; } |
| 1253 | 1245 |
| 1254 class B implements A { | 1246 class B implements A { |
| 1255 const B(); | 1247 const B(); |
| 1256 | 1248 |
| 1257 operator ==(o) => true; | 1249 operator ==(o) => true; |
| 1258 } | 1250 } |
| 1259 | 1251 |
| 1260 main() { | 1252 main() { |
| 1261 var m = const { const A(): 42 }; | 1253 var m = const { const A(): 42 }; |
| 1262 }'''); | 1254 }'''); |
| 1263 resolve(source); | 1255 resolve(source); |
| 1264 assertErrors(source, [ | 1256 assertErrors(source, |
| 1265 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS | 1257 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
| 1266 ]); | |
| 1267 verify([source]); | 1258 verify([source]); |
| 1268 } | 1259 } |
| 1269 | 1260 |
| 1270 void test_constMapKeyTypeImplementsEquals_super() { | 1261 void test_constMapKeyTypeImplementsEquals_super() { |
| 1271 Source source = addSource(r''' | 1262 Source source = addSource(r''' |
| 1272 class A { | 1263 class A { |
| 1273 const A(); | 1264 const A(); |
| 1274 operator ==(other) => false; | 1265 operator ==(other) => false; |
| 1275 } | 1266 } |
| 1276 class B extends A { | 1267 class B extends A { |
| 1277 const B(); | 1268 const B(); |
| 1278 } | 1269 } |
| 1279 main() { | 1270 main() { |
| 1280 const {const B() : 0}; | 1271 const {const B() : 0}; |
| 1281 }'''); | 1272 }'''); |
| 1282 resolve(source); | 1273 resolve(source); |
| 1283 assertErrors(source, [ | 1274 assertErrors(source, |
| 1284 CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS | 1275 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
| 1285 ]); | |
| 1286 verify([source]); | 1276 verify([source]); |
| 1287 } | 1277 } |
| 1288 | 1278 |
| 1289 void test_constWithInvalidTypeParameters() { | 1279 void test_constWithInvalidTypeParameters() { |
| 1290 Source source = addSource(r''' | 1280 Source source = addSource(r''' |
| 1291 class A { | 1281 class A { |
| 1292 const A(); | 1282 const A(); |
| 1293 } | 1283 } |
| 1294 f() { return const A<A>(); }'''); | 1284 f() { return const A<A>(); }'''); |
| 1295 resolve(source); | 1285 resolve(source); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 | 1424 |
| 1435 void test_constWithUndefinedConstructorDefault() { | 1425 void test_constWithUndefinedConstructorDefault() { |
| 1436 Source source = addSource(r''' | 1426 Source source = addSource(r''' |
| 1437 class A { | 1427 class A { |
| 1438 const A.name(); | 1428 const A.name(); |
| 1439 } | 1429 } |
| 1440 f() { | 1430 f() { |
| 1441 return const A(); | 1431 return const A(); |
| 1442 }'''); | 1432 }'''); |
| 1443 resolve(source); | 1433 resolve(source); |
| 1444 assertErrors(source, [ | 1434 assertErrors(source, |
| 1445 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT | 1435 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]); |
| 1446 ]); | |
| 1447 verify([source]); | 1436 verify([source]); |
| 1448 } | 1437 } |
| 1449 | 1438 |
| 1450 void test_defaultValueInFunctionTypeAlias() { | 1439 void test_defaultValueInFunctionTypeAlias() { |
| 1451 Source source = addSource("typedef F([x = 0]);"); | 1440 Source source = addSource("typedef F([x = 0]);"); |
| 1452 resolve(source); | 1441 resolve(source); |
| 1453 assertErrors( | 1442 assertErrors( |
| 1454 source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]); | 1443 source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]); |
| 1455 verify([source]); | 1444 verify([source]); |
| 1456 } | 1445 } |
| 1457 | 1446 |
| 1458 void test_defaultValueInFunctionTypedParameter_named() { | 1447 void test_defaultValueInFunctionTypedParameter_named() { |
| 1459 Source source = addSource("f(g({p: null})) {}"); | 1448 Source source = addSource("f(g({p: null})) {}"); |
| 1460 resolve(source); | 1449 resolve(source); |
| 1461 assertErrors(source, [ | 1450 assertErrors(source, |
| 1462 CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER | 1451 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); |
| 1463 ]); | |
| 1464 verify([source]); | 1452 verify([source]); |
| 1465 } | 1453 } |
| 1466 | 1454 |
| 1467 void test_defaultValueInFunctionTypedParameter_optional() { | 1455 void test_defaultValueInFunctionTypedParameter_optional() { |
| 1468 Source source = addSource("f(g([p = null])) {}"); | 1456 Source source = addSource("f(g([p = null])) {}"); |
| 1469 resolve(source); | 1457 resolve(source); |
| 1470 assertErrors(source, [ | 1458 assertErrors(source, |
| 1471 CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER | 1459 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); |
| 1472 ]); | |
| 1473 verify([source]); | 1460 verify([source]); |
| 1474 } | 1461 } |
| 1475 | 1462 |
| 1476 void test_defaultValueInRedirectingFactoryConstructor() { | 1463 void test_defaultValueInRedirectingFactoryConstructor() { |
| 1477 Source source = addSource(r''' | 1464 Source source = addSource(r''' |
| 1478 class A { | 1465 class A { |
| 1479 factory A([int x = 0]) = B; | 1466 factory A([int x = 0]) = B; |
| 1480 } | 1467 } |
| 1481 | 1468 |
| 1482 class B implements A { | 1469 class B implements A { |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1904 verify([source]); | 1891 verify([source]); |
| 1905 } | 1892 } |
| 1906 | 1893 |
| 1907 void test_fieldInitializedByMultipleInitializers() { | 1894 void test_fieldInitializedByMultipleInitializers() { |
| 1908 Source source = addSource(r''' | 1895 Source source = addSource(r''' |
| 1909 class A { | 1896 class A { |
| 1910 int x; | 1897 int x; |
| 1911 A() : x = 0, x = 1 {} | 1898 A() : x = 0, x = 1 {} |
| 1912 }'''); | 1899 }'''); |
| 1913 resolve(source); | 1900 resolve(source); |
| 1914 assertErrors(source, [ | 1901 assertErrors(source, |
| 1915 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS | 1902 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); |
| 1916 ]); | |
| 1917 verify([source]); | 1903 verify([source]); |
| 1918 } | 1904 } |
| 1919 | 1905 |
| 1920 void test_fieldInitializedByMultipleInitializers_multipleInits() { | 1906 void test_fieldInitializedByMultipleInitializers_multipleInits() { |
| 1921 Source source = addSource(r''' | 1907 Source source = addSource(r''' |
| 1922 class A { | 1908 class A { |
| 1923 int x; | 1909 int x; |
| 1924 A() : x = 0, x = 1, x = 2 {} | 1910 A() : x = 0, x = 1, x = 2 {} |
| 1925 }'''); | 1911 }'''); |
| 1926 resolve(source); | 1912 resolve(source); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1946 verify([source]); | 1932 verify([source]); |
| 1947 } | 1933 } |
| 1948 | 1934 |
| 1949 void test_fieldInitializedInParameterAndInitializer() { | 1935 void test_fieldInitializedInParameterAndInitializer() { |
| 1950 Source source = addSource(r''' | 1936 Source source = addSource(r''' |
| 1951 class A { | 1937 class A { |
| 1952 int x; | 1938 int x; |
| 1953 A(this.x) : x = 1 {} | 1939 A(this.x) : x = 1 {} |
| 1954 }'''); | 1940 }'''); |
| 1955 resolve(source); | 1941 resolve(source); |
| 1956 assertErrors(source, [ | 1942 assertErrors(source, |
| 1957 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER | 1943 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); |
| 1958 ]); | |
| 1959 verify([source]); | 1944 verify([source]); |
| 1960 } | 1945 } |
| 1961 | 1946 |
| 1962 void test_fieldInitializerFactoryConstructor() { | 1947 void test_fieldInitializerFactoryConstructor() { |
| 1963 Source source = addSource(r''' | 1948 Source source = addSource(r''' |
| 1964 class A { | 1949 class A { |
| 1965 int x; | 1950 int x; |
| 1966 factory A(this.x) {} | 1951 factory A(this.x) {} |
| 1967 }'''); | 1952 }'''); |
| 1968 resolve(source); | 1953 resolve(source); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1999 } | 1984 } |
| 2000 | 1985 |
| 2001 void test_fieldInitializerRedirectingConstructor_afterRedirection() { | 1986 void test_fieldInitializerRedirectingConstructor_afterRedirection() { |
| 2002 Source source = addSource(r''' | 1987 Source source = addSource(r''' |
| 2003 class A { | 1988 class A { |
| 2004 int x; | 1989 int x; |
| 2005 A.named() {} | 1990 A.named() {} |
| 2006 A() : this.named(), x = 42; | 1991 A() : this.named(), x = 42; |
| 2007 }'''); | 1992 }'''); |
| 2008 resolve(source); | 1993 resolve(source); |
| 2009 assertErrors(source, [ | 1994 assertErrors(source, |
| 2010 CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR | 1995 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); |
| 2011 ]); | |
| 2012 verify([source]); | 1996 verify([source]); |
| 2013 } | 1997 } |
| 2014 | 1998 |
| 2015 void test_fieldInitializerRedirectingConstructor_beforeRedirection() { | 1999 void test_fieldInitializerRedirectingConstructor_beforeRedirection() { |
| 2016 Source source = addSource(r''' | 2000 Source source = addSource(r''' |
| 2017 class A { | 2001 class A { |
| 2018 int x; | 2002 int x; |
| 2019 A.named() {} | 2003 A.named() {} |
| 2020 A() : x = 42, this.named(); | 2004 A() : x = 42, this.named(); |
| 2021 }'''); | 2005 }'''); |
| 2022 resolve(source); | 2006 resolve(source); |
| 2023 assertErrors(source, [ | 2007 assertErrors(source, |
| 2024 CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR | 2008 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); |
| 2025 ]); | |
| 2026 verify([source]); | 2009 verify([source]); |
| 2027 } | 2010 } |
| 2028 | 2011 |
| 2029 void test_fieldInitializingFormalRedirectingConstructor() { | 2012 void test_fieldInitializingFormalRedirectingConstructor() { |
| 2030 Source source = addSource(r''' | 2013 Source source = addSource(r''' |
| 2031 class A { | 2014 class A { |
| 2032 int x; | 2015 int x; |
| 2033 A.named() {} | 2016 A.named() {} |
| 2034 A(this.x) : this.named(); | 2017 A(this.x) : this.named(); |
| 2035 }'''); | 2018 }'''); |
| 2036 resolve(source); | 2019 resolve(source); |
| 2037 assertErrors(source, [ | 2020 assertErrors(source, |
| 2038 CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR | 2021 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); |
| 2039 ]); | |
| 2040 verify([source]); | 2022 verify([source]); |
| 2041 } | 2023 } |
| 2042 | 2024 |
| 2043 void test_finalInitializedMultipleTimes_initializers() { | 2025 void test_finalInitializedMultipleTimes_initializers() { |
| 2044 Source source = addSource(r''' | 2026 Source source = addSource(r''' |
| 2045 class A { | 2027 class A { |
| 2046 final x; | 2028 final x; |
| 2047 A() : x = 0, x = 0 {} | 2029 A() : x = 0, x = 0 {} |
| 2048 }'''); | 2030 }'''); |
| 2049 resolve(source); | 2031 resolve(source); |
| 2050 assertErrors(source, [ | 2032 assertErrors(source, |
| 2051 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS | 2033 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); |
| 2052 ]); | |
| 2053 verify([source]); | 2034 verify([source]); |
| 2054 } | 2035 } |
| 2055 | 2036 |
| 2056 /** | 2037 /** |
| 2057 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests
the | 2038 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests
the |
| 2058 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided
here to show | 2039 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided
here to show |
| 2059 * coverage over all of the permutations of initializers in constructor declar
ations. | 2040 * coverage over all of the permutations of initializers in constructor declar
ations. |
| 2060 * | 2041 * |
| 2061 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of | 2042 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of |
| 2062 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead
of the broader code | 2043 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead
of the broader code |
| 2063 */ | 2044 */ |
| 2064 void test_finalInitializedMultipleTimes_initializingFormal_initializer() { | 2045 void test_finalInitializedMultipleTimes_initializingFormal_initializer() { |
| 2065 Source source = addSource(r''' | 2046 Source source = addSource(r''' |
| 2066 class A { | 2047 class A { |
| 2067 final x; | 2048 final x; |
| 2068 A(this.x) : x = 0 {} | 2049 A(this.x) : x = 0 {} |
| 2069 }'''); | 2050 }'''); |
| 2070 resolve(source); | 2051 resolve(source); |
| 2071 assertErrors(source, [ | 2052 assertErrors(source, |
| 2072 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER | 2053 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); |
| 2073 ]); | |
| 2074 verify([source]); | 2054 verify([source]); |
| 2075 } | 2055 } |
| 2076 | 2056 |
| 2077 void test_finalInitializedMultipleTimes_initializingFormals() { | 2057 void test_finalInitializedMultipleTimes_initializingFormals() { |
| 2078 Source source = addSource(r''' | 2058 Source source = addSource(r''' |
| 2079 class A { | 2059 class A { |
| 2080 final x; | 2060 final x; |
| 2081 A(this.x, this.x) {} | 2061 A(this.x, this.x) {} |
| 2082 }'''); | 2062 }'''); |
| 2083 resolve(source); | 2063 resolve(source); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]); | 2576 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]); |
| 2597 verify([source]); | 2577 verify([source]); |
| 2598 } | 2578 } |
| 2599 | 2579 |
| 2600 void test_initializingFormalForNonExistentField() { | 2580 void test_initializingFormalForNonExistentField() { |
| 2601 Source source = addSource(r''' | 2581 Source source = addSource(r''' |
| 2602 class A { | 2582 class A { |
| 2603 A(this.x) {} | 2583 A(this.x) {} |
| 2604 }'''); | 2584 }'''); |
| 2605 resolve(source); | 2585 resolve(source); |
| 2606 assertErrors(source, [ | 2586 assertErrors(source, |
| 2607 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD | 2587 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
| 2608 ]); | |
| 2609 verify([source]); | 2588 verify([source]); |
| 2610 } | 2589 } |
| 2611 | 2590 |
| 2612 void test_initializingFormalForNonExistentField_notInEnclosingClass() { | 2591 void test_initializingFormalForNonExistentField_notInEnclosingClass() { |
| 2613 Source source = addSource(r''' | 2592 Source source = addSource(r''' |
| 2614 class A { | 2593 class A { |
| 2615 int x; | 2594 int x; |
| 2616 } | 2595 } |
| 2617 class B extends A { | 2596 class B extends A { |
| 2618 B(this.x) {} | 2597 B(this.x) {} |
| 2619 }'''); | 2598 }'''); |
| 2620 resolve(source); | 2599 resolve(source); |
| 2621 assertErrors(source, [ | 2600 assertErrors(source, |
| 2622 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD | 2601 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
| 2623 ]); | |
| 2624 verify([source]); | 2602 verify([source]); |
| 2625 } | 2603 } |
| 2626 | 2604 |
| 2627 void test_initializingFormalForNonExistentField_optional() { | 2605 void test_initializingFormalForNonExistentField_optional() { |
| 2628 Source source = addSource(r''' | 2606 Source source = addSource(r''' |
| 2629 class A { | 2607 class A { |
| 2630 A([this.x]) {} | 2608 A([this.x]) {} |
| 2631 }'''); | 2609 }'''); |
| 2632 resolve(source); | 2610 resolve(source); |
| 2633 assertErrors(source, [ | 2611 assertErrors(source, |
| 2634 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD | 2612 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
| 2635 ]); | |
| 2636 verify([source]); | 2613 verify([source]); |
| 2637 } | 2614 } |
| 2638 | 2615 |
| 2639 void test_initializingFormalForNonExistentField_synthetic() { | 2616 void test_initializingFormalForNonExistentField_synthetic() { |
| 2640 Source source = addSource(r''' | 2617 Source source = addSource(r''' |
| 2641 class A { | 2618 class A { |
| 2642 int get x => 1; | 2619 int get x => 1; |
| 2643 A(this.x) {} | 2620 A(this.x) {} |
| 2644 }'''); | 2621 }'''); |
| 2645 resolve(source); | 2622 resolve(source); |
| 2646 assertErrors(source, [ | 2623 assertErrors(source, |
| 2647 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD | 2624 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
| 2648 ]); | |
| 2649 verify([source]); | 2625 verify([source]); |
| 2650 } | 2626 } |
| 2651 | 2627 |
| 2652 void test_initializingFormalForStaticField() { | 2628 void test_initializingFormalForStaticField() { |
| 2653 Source source = addSource(r''' | 2629 Source source = addSource(r''' |
| 2654 class A { | 2630 class A { |
| 2655 static int x; | 2631 static int x; |
| 2656 A([this.x]) {} | 2632 A([this.x]) {} |
| 2657 }'''); | 2633 }'''); |
| 2658 resolve(source); | 2634 resolve(source); |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3666 } | 3642 } |
| 3667 | 3643 |
| 3668 void test_multipleRedirectingConstructorInvocations() { | 3644 void test_multipleRedirectingConstructorInvocations() { |
| 3669 Source source = addSource(r''' | 3645 Source source = addSource(r''' |
| 3670 class A { | 3646 class A { |
| 3671 A() : this.a(), this.b(); | 3647 A() : this.a(), this.b(); |
| 3672 A.a() {} | 3648 A.a() {} |
| 3673 A.b() {} | 3649 A.b() {} |
| 3674 }'''); | 3650 }'''); |
| 3675 resolve(source); | 3651 resolve(source); |
| 3676 assertErrors(source, [ | 3652 assertErrors(source, |
| 3677 CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS | 3653 [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS]); |
| 3678 ]); | |
| 3679 verify([source]); | 3654 verify([source]); |
| 3680 } | 3655 } |
| 3681 | 3656 |
| 3682 void test_multipleSuperInitializers() { | 3657 void test_multipleSuperInitializers() { |
| 3683 Source source = addSource(r''' | 3658 Source source = addSource(r''' |
| 3684 class A {} | 3659 class A {} |
| 3685 class B extends A { | 3660 class B extends A { |
| 3686 B() : super(), super() {} | 3661 B() : super(), super() {} |
| 3687 }'''); | 3662 }'''); |
| 3688 resolve(source); | 3663 resolve(source); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3759 class B { | 3734 class B { |
| 3760 B({x}); | 3735 B({x}); |
| 3761 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3736 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
| 3762 } | 3737 } |
| 3763 class Mixed = B with M; | 3738 class Mixed = B with M; |
| 3764 class C extends Mixed { | 3739 class C extends Mixed { |
| 3765 C(x) : super(); | 3740 C(x) : super(); |
| 3766 } | 3741 } |
| 3767 '''); | 3742 '''); |
| 3768 resolve(source); | 3743 resolve(source); |
| 3769 assertErrors(source, [ | 3744 assertErrors(source, |
| 3770 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 3745 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
| 3771 ]); | |
| 3772 verify([source]); | 3746 verify([source]); |
| 3773 } | 3747 } |
| 3774 | 3748 |
| 3775 void test_noDefaultSuperConstructorExplicit_mixinAppWithNamedParam() { | 3749 void test_noDefaultSuperConstructorExplicit_mixinAppWithNamedParam() { |
| 3776 Source source = addSource(r''' | 3750 Source source = addSource(r''' |
| 3777 class M {} | 3751 class M {} |
| 3778 class B { | 3752 class B { |
| 3779 B({x}); | 3753 B({x}); |
| 3780 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3754 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
| 3781 } | 3755 } |
| 3782 class Mixed = B with M; | 3756 class Mixed = B with M; |
| 3783 class C extends Mixed { | 3757 class C extends Mixed { |
| 3784 C(); | 3758 C(); |
| 3785 } | 3759 } |
| 3786 '''); | 3760 '''); |
| 3787 resolve(source); | 3761 resolve(source); |
| 3788 assertErrors(source, [ | 3762 assertErrors(source, |
| 3789 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 3763 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
| 3790 ]); | |
| 3791 verify([source]); | 3764 verify([source]); |
| 3792 } | 3765 } |
| 3793 | 3766 |
| 3794 void test_noDefaultSuperConstructorExplicit_MixinAppWithNamedSuperCall() { | 3767 void test_noDefaultSuperConstructorExplicit_MixinAppWithNamedSuperCall() { |
| 3795 Source source = addSource(r''' | 3768 Source source = addSource(r''' |
| 3796 class M {} | 3769 class M {} |
| 3797 class B { | 3770 class B { |
| 3798 B.named({x}); | 3771 B.named({x}); |
| 3799 B.named2(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3772 B.named2(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
| 3800 } | 3773 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3815 class B { | 3788 class B { |
| 3816 B([x]); | 3789 B([x]); |
| 3817 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3790 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
| 3818 } | 3791 } |
| 3819 class Mixed = B with M; | 3792 class Mixed = B with M; |
| 3820 class C extends Mixed { | 3793 class C extends Mixed { |
| 3821 C(); | 3794 C(); |
| 3822 } | 3795 } |
| 3823 '''); | 3796 '''); |
| 3824 resolve(source); | 3797 resolve(source); |
| 3825 assertErrors(source, [ | 3798 assertErrors(source, |
| 3826 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 3799 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
| 3827 ]); | |
| 3828 verify([source]); | 3800 verify([source]); |
| 3829 } | 3801 } |
| 3830 | 3802 |
| 3831 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() { | 3803 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() { |
| 3832 Source source = addSource(r''' | 3804 Source source = addSource(r''' |
| 3833 class M {} | 3805 class M {} |
| 3834 class B { | 3806 class B { |
| 3835 B({x}); | 3807 B({x}); |
| 3836 B.other(); | 3808 B.other(); |
| 3837 } | 3809 } |
| 3838 class C extends B with M { | 3810 class C extends B with M { |
| 3839 C(x) : super(); | 3811 C(x) : super(); |
| 3840 } | 3812 } |
| 3841 '''); | 3813 '''); |
| 3842 resolve(source); | 3814 resolve(source); |
| 3843 assertErrors(source, [ | 3815 assertErrors(source, |
| 3844 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 3816 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
| 3845 ]); | |
| 3846 verify([source]); | 3817 verify([source]); |
| 3847 } | 3818 } |
| 3848 | 3819 |
| 3849 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() { | 3820 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() { |
| 3850 Source source = addSource(r''' | 3821 Source source = addSource(r''' |
| 3851 class M {} | 3822 class M {} |
| 3852 class B { | 3823 class B { |
| 3853 B({x}); | 3824 B({x}); |
| 3854 B.named(); | 3825 B.named(); |
| 3855 } | 3826 } |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4707 void test_recursiveFactoryRedirect_directSelfReference() { | 4678 void test_recursiveFactoryRedirect_directSelfReference() { |
| 4708 Source source = addSource(r''' | 4679 Source source = addSource(r''' |
| 4709 class A { | 4680 class A { |
| 4710 factory A() = A; | 4681 factory A() = A; |
| 4711 }'''); | 4682 }'''); |
| 4712 resolve(source); | 4683 resolve(source); |
| 4713 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); | 4684 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); |
| 4714 verify([source]); | 4685 verify([source]); |
| 4715 } | 4686 } |
| 4716 | 4687 |
| 4688 void test_recursiveFactoryRedirect_diverging() { |
| 4689 // Analysis should terminate even though the redirections don't reach a |
| 4690 // fixed point. (C<int> redirects to C<C<int>>, then to C<C<C<int>>>, and |
| 4691 // so on). |
| 4692 Source source = addSource(''' |
| 4693 class C<T> { |
| 4694 const factory C() = C<C<T>>; |
| 4695 } |
| 4696 main() { |
| 4697 const C<int>(); |
| 4698 } |
| 4699 '''); |
| 4700 resolve(source); |
| 4701 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); |
| 4702 verify([source]); |
| 4703 } |
| 4704 |
| 4717 void test_recursiveFactoryRedirect_generic() { | 4705 void test_recursiveFactoryRedirect_generic() { |
| 4718 Source source = addSource(r''' | 4706 Source source = addSource(r''' |
| 4719 class A<T> implements B<T> { | 4707 class A<T> implements B<T> { |
| 4720 factory A() = C; | 4708 factory A() = C; |
| 4721 } | 4709 } |
| 4722 class B<T> implements C<T> { | 4710 class B<T> implements C<T> { |
| 4723 factory B() = A; | 4711 factory B() = A; |
| 4724 } | 4712 } |
| 4725 class C<T> implements A<T> { | 4713 class C<T> implements A<T> { |
| 4726 factory C() = B; | 4714 factory C() = B; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4898 resolve(source); | 4886 resolve(source); |
| 4899 assertErrors(source, [ | 4887 assertErrors(source, [ |
| 4900 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS | 4888 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS |
| 4901 ]); | 4889 ]); |
| 4902 verify([source]); | 4890 verify([source]); |
| 4903 } | 4891 } |
| 4904 | 4892 |
| 4905 void test_recursiveInterfaceInheritanceBaseCaseWith() { | 4893 void test_recursiveInterfaceInheritanceBaseCaseWith() { |
| 4906 Source source = addSource("class M = Object with M;"); | 4894 Source source = addSource("class M = Object with M;"); |
| 4907 resolve(source); | 4895 resolve(source); |
| 4908 assertErrors(source, [ | 4896 assertErrors(source, |
| 4909 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH | 4897 [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH]); |
| 4910 ]); | |
| 4911 verify([source]); | 4898 verify([source]); |
| 4912 } | 4899 } |
| 4913 | 4900 |
| 4914 void test_redirectGenerativeToMissingConstructor() { | 4901 void test_redirectGenerativeToMissingConstructor() { |
| 4915 Source source = addSource(r''' | 4902 Source source = addSource(r''' |
| 4916 class A { | 4903 class A { |
| 4917 A() : this.noSuchConstructor(); | 4904 A() : this.noSuchConstructor(); |
| 4918 }'''); | 4905 }'''); |
| 4919 resolve(source); | 4906 resolve(source); |
| 4920 assertErrors(source, [ | 4907 assertErrors(source, |
| 4921 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR | 4908 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); |
| 4922 ]); | |
| 4923 } | 4909 } |
| 4924 | 4910 |
| 4925 void test_redirectGenerativeToNonGenerativeConstructor() { | 4911 void test_redirectGenerativeToNonGenerativeConstructor() { |
| 4926 Source source = addSource(r''' | 4912 Source source = addSource(r''' |
| 4927 class A { | 4913 class A { |
| 4928 A() : this.x(); | 4914 A() : this.x(); |
| 4929 factory A.x() => null; | 4915 factory A.x() => null; |
| 4930 }'''); | 4916 }'''); |
| 4931 resolve(source); | 4917 resolve(source); |
| 4932 assertErrors(source, [ | 4918 assertErrors(source, [ |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5398 | 5384 |
| 5399 void test_undefinedConstructorInInitializer_explicit_unnamed() { | 5385 void test_undefinedConstructorInInitializer_explicit_unnamed() { |
| 5400 Source source = addSource(r''' | 5386 Source source = addSource(r''' |
| 5401 class A { | 5387 class A { |
| 5402 A.named() {} | 5388 A.named() {} |
| 5403 } | 5389 } |
| 5404 class B extends A { | 5390 class B extends A { |
| 5405 B() : super(); | 5391 B() : super(); |
| 5406 }'''); | 5392 }'''); |
| 5407 resolve(source); | 5393 resolve(source); |
| 5408 assertErrors(source, [ | 5394 assertErrors(source, |
| 5409 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 5395 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
| 5410 ]); | |
| 5411 verify([source]); | 5396 verify([source]); |
| 5412 } | 5397 } |
| 5413 | 5398 |
| 5414 void test_undefinedConstructorInInitializer_implicit() { | 5399 void test_undefinedConstructorInInitializer_implicit() { |
| 5415 Source source = addSource(r''' | 5400 Source source = addSource(r''' |
| 5416 class A { | 5401 class A { |
| 5417 A.named() {} | 5402 A.named() {} |
| 5418 } | 5403 } |
| 5419 class B extends A { | 5404 class B extends A { |
| 5420 B(); | 5405 B(); |
| 5421 }'''); | 5406 }'''); |
| 5422 resolve(source); | 5407 resolve(source); |
| 5423 assertErrors(source, [ | 5408 assertErrors(source, |
| 5424 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 5409 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
| 5425 ]); | |
| 5426 verify([source]); | 5410 verify([source]); |
| 5427 } | 5411 } |
| 5428 | 5412 |
| 5429 void test_undefinedNamedParameter() { | 5413 void test_undefinedNamedParameter() { |
| 5430 Source source = addSource(r''' | 5414 Source source = addSource(r''' |
| 5431 class A { | 5415 class A { |
| 5432 const A(); | 5416 const A(); |
| 5433 } | 5417 } |
| 5434 main() { | 5418 main() { |
| 5435 const A(p: 0); | 5419 const A(p: 0); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5494 _check_wrongNumberOfParametersForOperator1(">>"); | 5478 _check_wrongNumberOfParametersForOperator1(">>"); |
| 5495 _check_wrongNumberOfParametersForOperator1("[]"); | 5479 _check_wrongNumberOfParametersForOperator1("[]"); |
| 5496 } | 5480 } |
| 5497 | 5481 |
| 5498 void test_wrongNumberOfParametersForOperator_minus() { | 5482 void test_wrongNumberOfParametersForOperator_minus() { |
| 5499 Source source = addSource(r''' | 5483 Source source = addSource(r''' |
| 5500 class A { | 5484 class A { |
| 5501 operator -(a, b) {} | 5485 operator -(a, b) {} |
| 5502 }'''); | 5486 }'''); |
| 5503 resolve(source); | 5487 resolve(source); |
| 5504 assertErrors(source, [ | 5488 assertErrors(source, |
| 5505 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS | 5489 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS]); |
| 5506 ]); | |
| 5507 verify([source]); | 5490 verify([source]); |
| 5508 reset(); | 5491 reset(); |
| 5509 } | 5492 } |
| 5510 | 5493 |
| 5511 void test_wrongNumberOfParametersForOperator_tilde() { | 5494 void test_wrongNumberOfParametersForOperator_tilde() { |
| 5512 _check_wrongNumberOfParametersForOperator("~", "a"); | 5495 _check_wrongNumberOfParametersForOperator("~", "a"); |
| 5513 _check_wrongNumberOfParametersForOperator("~", "a, b"); | 5496 _check_wrongNumberOfParametersForOperator("~", "a, b"); |
| 5514 } | 5497 } |
| 5515 | 5498 |
| 5516 void test_wrongNumberOfParametersForSetter_function_named() { | 5499 void test_wrongNumberOfParametersForSetter_function_named() { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5691 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 5674 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
| 5692 verify([source]); | 5675 verify([source]); |
| 5693 reset(); | 5676 reset(); |
| 5694 } | 5677 } |
| 5695 | 5678 |
| 5696 void _check_wrongNumberOfParametersForOperator1(String name) { | 5679 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 5697 _check_wrongNumberOfParametersForOperator(name, ""); | 5680 _check_wrongNumberOfParametersForOperator(name, ""); |
| 5698 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 5681 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 5699 } | 5682 } |
| 5700 } | 5683 } |
| OLD | NEW |