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/source_io.dart'; | 7 import 'package:analyzer/src/generated/source_io.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/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1392 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1392 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1393 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | 1393 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
1394 verify([source]); | 1394 verify([source]); |
1395 } | 1395 } |
1396 | 1396 |
1397 void test_extendsDisallowedClass_classTypeAlias_bool() { | 1397 void test_extendsDisallowedClass_classTypeAlias_bool() { |
1398 Source source = addSource(r''' | 1398 Source source = addSource(r''' |
1399 class M {} | 1399 class M {} |
1400 class C = bool with M;'''); | 1400 class C = bool with M;'''); |
1401 resolve(source); | 1401 resolve(source); |
1402 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1402 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1403 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | |
Brian Wilkerson
2014/11/07 16:59:32
It would be good to disable the second error if th
Paul Berry
2014/11/07 17:31:01
Good point. I'll do this in a follow-up CL, as we
| |
1403 verify([source]); | 1404 verify([source]); |
1404 } | 1405 } |
1405 | 1406 |
1406 void test_extendsDisallowedClass_classTypeAlias_double() { | 1407 void test_extendsDisallowedClass_classTypeAlias_double() { |
1407 Source source = addSource(r''' | 1408 Source source = addSource(r''' |
1408 class M {} | 1409 class M {} |
1409 class C = double with M;'''); | 1410 class C = double with M;'''); |
1410 resolve(source); | 1411 resolve(source); |
1411 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1412 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
1412 verify([source]); | 1413 verify([source]); |
1413 } | 1414 } |
1414 | 1415 |
1415 void test_extendsDisallowedClass_classTypeAlias_int() { | 1416 void test_extendsDisallowedClass_classTypeAlias_int() { |
1416 Source source = addSource(r''' | 1417 Source source = addSource(r''' |
1417 class M {} | 1418 class M {} |
1418 class C = int with M;'''); | 1419 class C = int with M;'''); |
1419 resolve(source); | 1420 resolve(source); |
1420 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1421 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1422 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | |
1421 verify([source]); | 1423 verify([source]); |
1422 } | 1424 } |
1423 | 1425 |
1424 void test_extendsDisallowedClass_classTypeAlias_Null() { | 1426 void test_extendsDisallowedClass_classTypeAlias_Null() { |
1425 Source source = addSource(r''' | 1427 Source source = addSource(r''' |
1426 class M {} | 1428 class M {} |
1427 class C = Null with M;'''); | 1429 class C = Null with M;'''); |
1428 resolve(source); | 1430 resolve(source); |
1429 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1431 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
1430 verify([source]); | 1432 verify([source]); |
1431 } | 1433 } |
1432 | 1434 |
1433 void test_extendsDisallowedClass_classTypeAlias_num() { | 1435 void test_extendsDisallowedClass_classTypeAlias_num() { |
1434 Source source = addSource(r''' | 1436 Source source = addSource(r''' |
1435 class M {} | 1437 class M {} |
1436 class C = num with M;'''); | 1438 class C = num with M;'''); |
1437 resolve(source); | 1439 resolve(source); |
1438 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1440 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
1439 verify([source]); | 1441 verify([source]); |
1440 } | 1442 } |
1441 | 1443 |
1442 void test_extendsDisallowedClass_classTypeAlias_String() { | 1444 void test_extendsDisallowedClass_classTypeAlias_String() { |
1443 Source source = addSource(r''' | 1445 Source source = addSource(r''' |
1444 class M {} | 1446 class M {} |
1445 class C = String with M;'''); | 1447 class C = String with M;'''); |
1446 resolve(source); | 1448 resolve(source); |
1447 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1449 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1450 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | |
1448 verify([source]); | 1451 verify([source]); |
1449 } | 1452 } |
1450 | 1453 |
1451 void test_extendsEnum() { | 1454 void test_extendsEnum() { |
1452 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 1455 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
1453 analysisOptions.enableEnum = true; | 1456 analysisOptions.enableEnum = true; |
1454 resetWithOptions(analysisOptions); | 1457 resetWithOptions(analysisOptions); |
1455 Source source = addSource(r''' | 1458 Source source = addSource(r''' |
1456 enum E { ONE } | 1459 enum E { ONE } |
1457 class A extends E {}'''); | 1460 class A extends E {}'''); |
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2901 r''' | 2904 r''' |
2902 library lib1; | 2905 library lib1; |
2903 class A {}''', | 2906 class A {}''', |
2904 r''' | 2907 r''' |
2905 library root; | 2908 library root; |
2906 import 'lib1.dart' deferred as a; | 2909 import 'lib1.dart' deferred as a; |
2907 class B {} | 2910 class B {} |
2908 class C = B with a.A;'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUP PORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]); | 2911 class C = B with a.A;'''], <ErrorCode> [ParserErrorCode.DEFERRED_IMPORTS_NOT_SUP PORTED], <ErrorCode> [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]); |
2909 } | 2912 } |
2910 | 2913 |
2914 void test_mixinHasNoConstructors_mixinApp() { | |
2915 Source source = addSource(r''' | |
2916 class B { | |
2917 B({x}); | |
2918 } | |
2919 class M {} | |
2920 class C = B with M; | |
2921 '''); | |
2922 resolve(source); | |
2923 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | |
2924 verify([source]); | |
2925 } | |
2926 | |
2927 void test_mixinHasNoConstructors_mixinClass() { | |
2928 Source source = addSource(r''' | |
2929 class B { | |
2930 B({x}); | |
2931 } | |
2932 class M {} | |
2933 class C extends B with M {} | |
2934 '''); | |
2935 resolve(source); | |
2936 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]); | |
2937 verify([source]); | |
2938 } | |
2939 | |
2911 void test_mixinInheritsFromNotObject_classDeclaration_extends() { | 2940 void test_mixinInheritsFromNotObject_classDeclaration_extends() { |
2912 Source source = addSource(r''' | 2941 Source source = addSource(r''' |
2913 class A {} | 2942 class A {} |
2914 class B extends A {} | 2943 class B extends A {} |
2915 class C extends Object with B {}'''); | 2944 class C extends Object with B {}'''); |
2916 resolve(source); | 2945 resolve(source); |
2917 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); | 2946 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
2918 verify([source]); | 2947 verify([source]); |
2919 } | 2948 } |
2920 | 2949 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3189 A(p); | 3218 A(p); |
3190 } | 3219 } |
3191 class B extends A { | 3220 class B extends A { |
3192 B() {} | 3221 B() {} |
3193 }'''); | 3222 }'''); |
3194 resolve(source); | 3223 resolve(source); |
3195 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPL ICIT]); | 3224 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPL ICIT]); |
3196 verify([source]); | 3225 verify([source]); |
3197 } | 3226 } |
3198 | 3227 |
3228 void test_noDefaultSuperConstructorExplicit_MixinAppWithDirectSuperCall() { | |
3229 Source source = addSource(r''' | |
3230 class M {} | |
3231 class B { | |
3232 B({x}); | |
3233 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | |
3234 } | |
3235 class Mixed = B with M; | |
3236 class C extends Mixed { | |
3237 C(x) : super(); | |
3238 } | |
3239 '''); | |
3240 resolve(source); | |
3241 assertErrors(source, [ | |
3242 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | |
3243 verify([source]); | |
3244 } | |
3245 | |
3246 void test_noDefaultSuperConstructorExplicit_MixinAppWithNamedSuperCall() { | |
3247 Source source = addSource(r''' | |
3248 class M {} | |
3249 class B { | |
3250 B.named({x}); | |
3251 B.named2(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | |
3252 } | |
3253 class Mixed = B with M; | |
3254 class C extends Mixed { | |
3255 C(x) : super.named(); | |
3256 } | |
3257 '''); | |
3258 resolve(source); | |
3259 assertErrors(source, [ | |
3260 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); | |
3261 // Don't verify since call to super.named() can't be resolved. | |
3262 } | |
3263 | |
3264 void test_noDefaultSuperConstructorExplicit_mixinAppWithNamedParam() { | |
3265 Source source = addSource(r''' | |
3266 class M {} | |
3267 class B { | |
3268 B({x}); | |
3269 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | |
3270 } | |
3271 class Mixed = B with M; | |
3272 class C extends Mixed { | |
3273 C(); | |
3274 } | |
3275 '''); | |
3276 resolve(source); | |
3277 assertErrors(source, [ | |
3278 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | |
3279 verify([source]); | |
3280 } | |
3281 | |
3282 void test_noDefaultSuperConstructorExplicit_mixinAppWithOptionalParam() { | |
3283 Source source = addSource(r''' | |
3284 class M {} | |
3285 class B { | |
3286 B([x]); | |
3287 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | |
3288 } | |
3289 class Mixed = B with M; | |
3290 class C extends Mixed { | |
3291 C(); | |
3292 } | |
3293 '''); | |
3294 resolve(source); | |
3295 assertErrors(source, [ | |
3296 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | |
3297 verify([source]); | |
3298 } | |
3299 | |
3300 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() { | |
3301 Source source = addSource(r''' | |
3302 class M {} | |
3303 class B { | |
3304 B({x}); | |
3305 } | |
3306 class C extends B with M { | |
3307 C(x) : super(); | |
3308 } | |
3309 '''); | |
3310 resolve(source); | |
3311 assertErrors(source, [ | |
3312 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | |
3313 verify([source]); | |
3314 } | |
3315 | |
3316 void test_noDefaultSuperConstructorExplicit_MixinWithNamedSuperCall() { | |
3317 Source source = addSource(r''' | |
3318 class M {} | |
3319 class B { | |
3320 B.named({x}); | |
3321 } | |
3322 class C extends B with M { | |
3323 C(x) : super.named(); | |
3324 } | |
3325 '''); | |
3326 resolve(source); | |
3327 assertErrors(source, [ | |
3328 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); | |
3329 // Don't verify since call to super.named() can't be resolved. | |
3330 } | |
3331 | |
3332 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() { | |
3333 Source source = addSource(r''' | |
3334 class M {} | |
3335 class B { | |
3336 B({x}); | |
3337 } | |
3338 class C extends B with M { | |
3339 C(); | |
3340 } | |
3341 '''); | |
3342 resolve(source); | |
3343 assertErrors(source, [ | |
3344 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); | |
3345 verify([source]); | |
3346 } | |
3347 | |
3348 void test_noDefaultSuperConstructorExplicit_mixinWithOptionalParam() { | |
3349 Source source = addSource(r''' | |
3350 class M {} | |
3351 class B { | |
3352 B([x]); | |
3353 } | |
3354 class C extends B with M { | |
3355 C(); | |
3356 } | |
3357 '''); | |
3358 resolve(source); | |
3359 assertErrors(source, [ | |
3360 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); | |
3361 verify([source]); | |
3362 } | |
3363 | |
3364 void test_noDefaultSuperConstructorImplicit_mixinAppWithNamedParam() { | |
3365 Source source = addSource(r''' | |
3366 class M {} | |
3367 class B { | |
3368 B({x}); | |
3369 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | |
3370 } | |
3371 class Mixed = B with M; | |
3372 class C extends Mixed {} | |
3373 '''); | |
3374 resolve(source); | |
3375 assertErrors(source, [ | |
3376 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | |
3377 verify([source]); | |
3378 } | |
3379 | |
3380 void test_noDefaultSuperConstructorImplicit_mixinAppWithOptionalParam() { | |
3381 Source source = addSource(r''' | |
3382 class M {} | |
3383 class B { | |
3384 B([x]); | |
3385 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | |
3386 } | |
3387 class Mixed = B with M; | |
3388 class C extends Mixed {} | |
3389 '''); | |
3390 resolve(source); | |
3391 assertErrors(source, [ | |
3392 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | |
3393 verify([source]); | |
3394 } | |
3395 | |
3396 void test_noDefaultSuperConstructorImplicit_mixinWithNamedParam() { | |
3397 Source source = addSource(r''' | |
3398 class M {} | |
3399 class B { | |
3400 B({x}); | |
3401 } | |
3402 class C extends B with M {} | |
3403 '''); | |
3404 resolve(source); | |
3405 assertErrors(source, [ | |
3406 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | |
3407 verify([source]); | |
3408 } | |
3409 | |
3410 void test_noDefaultSuperConstructorImplicit_mixinWithOptionalParam() { | |
3411 Source source = addSource(r''' | |
3412 class M {} | |
3413 class B { | |
3414 B([x]); | |
3415 } | |
3416 class C extends B with M {} | |
3417 '''); | |
3418 resolve(source); | |
3419 assertErrors(source, [ | |
3420 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | |
3421 verify([source]); | |
3422 } | |
3423 | |
3199 void test_noDefaultSuperConstructorImplicit_superHasParameters() { | 3424 void test_noDefaultSuperConstructorImplicit_superHasParameters() { |
3200 Source source = addSource(r''' | 3425 Source source = addSource(r''' |
3201 class A { | 3426 class A { |
3202 A(p); | 3427 A(p); |
3203 } | 3428 } |
3204 class B extends A { | 3429 class B extends A { |
3205 }'''); | 3430 }'''); |
3206 resolve(source); | 3431 resolve(source); |
3207 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]); | 3432 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]); |
3208 verify([source]); | 3433 verify([source]); |
(...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4777 void _check_wrongNumberOfParametersForOperator1(String name) { | 5002 void _check_wrongNumberOfParametersForOperator1(String name) { |
4778 _check_wrongNumberOfParametersForOperator(name, ""); | 5003 _check_wrongNumberOfParametersForOperator(name, ""); |
4779 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 5004 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
4780 } | 5005 } |
4781 } | 5006 } |
4782 | 5007 |
4783 main() { | 5008 main() { |
4784 _ut.groupSep = ' | '; | 5009 _ut.groupSep = ' | '; |
4785 runReflectiveTests(CompileTimeErrorCodeTest); | 5010 runReflectiveTests(CompileTimeErrorCodeTest); |
4786 } | 5011 } |
OLD | NEW |