Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: pkg/analyzer/test/generated/compile_time_error_code_test.dart

Issue 724133003: Improve error reporting when a mixin application is invalid. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 2894 matching lines...) Expand 10 before | Expand all | Expand 10 after
2905 } 2905 }
2906 2906
2907 void test_mixinHasNoConstructors_mixinClass() { 2907 void test_mixinHasNoConstructors_mixinClass() {
2908 Source source = addSource(r''' 2908 Source source = addSource(r'''
2909 class B { 2909 class B {
2910 B({x}); 2910 B({x});
2911 } 2911 }
2912 class M {} 2912 class M {}
2913 class C extends B with M {} 2913 class C extends B with M {}
2914 '''); 2914 ''');
2915 // Note: the implicit call from C's default constructor to B() should not
2916 // generate a further error (despite the fact that it's not forwarded),
2917 // since CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job
2918 // of explaining the probem to the user.
2915 resolve(source); 2919 resolve(source);
2916 assertErrors(source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPL ICIT]); 2920 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
2917 verify([source]); 2921 verify([source]);
2918 } 2922 }
2919 2923
2924 void test_mixinHasNoConstructors_mixinClass_explicitSuperCall() {
2925 Source source = addSource(r'''
2926 class B {
2927 B({x});
2928 }
2929 class M {}
2930 class C extends B with M {
2931 C() : super();
2932 }
2933 ''');
2934 // Note: the explicit call from C() to B() should not generate a further
2935 // error (despite the fact that it's not forwarded), since
2936 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of
2937 // explaining the error to the user.
2938 resolve(source);
2939 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
2940 verify([source]);
2941 }
2942
2943 void test_mixinHasNoConstructors_mixinClass_implicitSuperCall() {
2944 Source source = addSource(r'''
2945 class B {
2946 B({x});
2947 }
2948 class M {}
2949 class C extends B with M {
2950 C();
2951 }
2952 ''');
2953 // Note: the implicit call from C() to B() should not generate a further
2954 // error (despite the fact that it's not forwarded), since
2955 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of
2956 // explaining the error to the user.
2957 resolve(source);
2958 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
2959 verify([source]);
2960 }
2961
2962 void test_mixinHasNoConstructors_mixinClass_namedSuperCall() {
2963 Source source = addSource(r'''
2964 class B {
2965 B.named({x});
2966 }
2967 class M {}
2968 class C extends B with M {
2969 C() : super.named();
2970 }
2971 ''');
2972 // Note: the explicit call from C() to B.named() should not generate a
2973 // further error (despite the fact that it's not forwarded), since
2974 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of
2975 // explaining the error to the user.
2976 resolve(source);
2977 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
2978 verify([source]);
2979 }
2980
2920 void test_mixinInheritsFromNotObject_classDeclaration_extends() { 2981 void test_mixinInheritsFromNotObject_classDeclaration_extends() {
2921 Source source = addSource(r''' 2982 Source source = addSource(r'''
2922 class A {} 2983 class A {}
2923 class B extends A {} 2984 class B extends A {}
2924 class C extends Object with B {}'''); 2985 class C extends Object with B {}''');
2925 resolve(source); 2986 resolve(source);
2926 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); 2987 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
2927 verify([source]); 2988 verify([source]);
2928 } 2989 }
2929 2990
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
3275 assertErrors(source, [ 3336 assertErrors(source, [
3276 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 3337 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
3277 verify([source]); 3338 verify([source]);
3278 } 3339 }
3279 3340
3280 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() { 3341 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() {
3281 Source source = addSource(r''' 3342 Source source = addSource(r'''
3282 class M {} 3343 class M {}
3283 class B { 3344 class B {
3284 B({x}); 3345 B({x});
3346 B.other();
3285 } 3347 }
3286 class C extends B with M { 3348 class C extends B with M {
3287 C(x) : super(); 3349 C(x) : super();
3288 } 3350 }
3289 '''); 3351 ''');
3290 resolve(source); 3352 resolve(source);
3291 assertErrors(source, [ 3353 assertErrors(source, [
3292 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); 3354 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]);
3293 verify([source]); 3355 verify([source]);
3294 } 3356 }
3295 3357
3296 void test_noDefaultSuperConstructorExplicit_MixinWithNamedSuperCall() { 3358 void test_noDefaultSuperConstructorExplicit_MixinWithNamedSuperCall() {
3297 Source source = addSource(r''' 3359 Source source = addSource(r'''
3298 class M {} 3360 class M {}
3299 class B { 3361 class B {
3300 B.named({x}); 3362 B.named({x});
3363 B.other();
3301 } 3364 }
3302 class C extends B with M { 3365 class C extends B with M {
3303 C(x) : super.named(); 3366 C(x) : super.named();
3304 } 3367 }
3305 '''); 3368 ''');
3306 resolve(source); 3369 resolve(source);
3307 assertErrors(source, [ 3370 assertErrors(source, [
3308 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); 3371 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]);
3309 // Don't verify since call to super.named() can't be resolved. 3372 // Don't verify since call to super.named() can't be resolved.
3310 } 3373 }
3311 3374
3312 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() { 3375 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() {
3313 Source source = addSource(r''' 3376 Source source = addSource(r'''
3314 class M {} 3377 class M {}
3315 class B { 3378 class B {
3316 B({x}); 3379 B({x});
3380 B.named();
3317 } 3381 }
3318 class C extends B with M { 3382 class C extends B with M {
3319 C(); 3383 C();
3320 } 3384 }
3321 '''); 3385 ''');
3322 resolve(source); 3386 resolve(source);
3323 assertErrors(source, [ 3387 assertErrors(source, [
3324 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); 3388 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]);
3325 verify([source]); 3389 verify([source]);
3326 } 3390 }
3327 3391
3328 void test_noDefaultSuperConstructorExplicit_mixinWithOptionalParam() { 3392 void test_noDefaultSuperConstructorExplicit_mixinWithOptionalParam() {
3329 Source source = addSource(r''' 3393 Source source = addSource(r'''
3330 class M {} 3394 class M {}
3331 class B { 3395 class B {
3332 B([x]); 3396 B([x]);
3397 B.other();
3333 } 3398 }
3334 class C extends B with M { 3399 class C extends B with M {
3335 C(); 3400 C();
3336 } 3401 }
3337 '''); 3402 ''');
3338 resolve(source); 3403 resolve(source);
3339 assertErrors(source, [ 3404 assertErrors(source, [
3340 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); 3405 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]);
3341 verify([source]); 3406 verify([source]);
3342 } 3407 }
(...skipping 28 matching lines...) Expand all
3371 assertErrors(source, [ 3436 assertErrors(source, [
3372 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3437 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
3373 verify([source]); 3438 verify([source]);
3374 } 3439 }
3375 3440
3376 void test_noDefaultSuperConstructorImplicit_mixinWithNamedParam() { 3441 void test_noDefaultSuperConstructorImplicit_mixinWithNamedParam() {
3377 Source source = addSource(r''' 3442 Source source = addSource(r'''
3378 class M {} 3443 class M {}
3379 class B { 3444 class B {
3380 B({x}); 3445 B({x});
3446 B.other();
3381 } 3447 }
3382 class C extends B with M {} 3448 class C extends B with M {}
3383 '''); 3449 ''');
3384 resolve(source); 3450 resolve(source);
3385 assertErrors(source, [ 3451 assertErrors(source, [
3386 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3452 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
3387 verify([source]); 3453 verify([source]);
3388 } 3454 }
3389 3455
3390 void test_noDefaultSuperConstructorImplicit_mixinWithOptionalParam() { 3456 void test_noDefaultSuperConstructorImplicit_mixinWithOptionalParam() {
3391 Source source = addSource(r''' 3457 Source source = addSource(r'''
3392 class M {} 3458 class M {}
3393 class B { 3459 class B {
3394 B([x]); 3460 B([x]);
3461 B.other();
3395 } 3462 }
3396 class C extends B with M {} 3463 class C extends B with M {}
3397 '''); 3464 ''');
3398 resolve(source); 3465 resolve(source);
3399 assertErrors(source, [ 3466 assertErrors(source, [
3400 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); 3467 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]);
3401 verify([source]); 3468 verify([source]);
3402 } 3469 }
3403 3470
3404 void test_noDefaultSuperConstructorImplicit_superHasParameters() { 3471 void test_noDefaultSuperConstructorImplicit_superHasParameters() {
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after
4982 void _check_wrongNumberOfParametersForOperator1(String name) { 5049 void _check_wrongNumberOfParametersForOperator1(String name) {
4983 _check_wrongNumberOfParametersForOperator(name, ""); 5050 _check_wrongNumberOfParametersForOperator(name, "");
4984 _check_wrongNumberOfParametersForOperator(name, "a, b"); 5051 _check_wrongNumberOfParametersForOperator(name, "a, b");
4985 } 5052 }
4986 } 5053 }
4987 5054
4988 main() { 5055 main() {
4989 _ut.groupSep = ' | '; 5056 _ut.groupSep = ' | ';
4990 runReflectiveTests(CompileTimeErrorCodeTest); 5057 runReflectiveTests(CompileTimeErrorCodeTest);
4991 } 5058 }
OLDNEW
« pkg/analyzer/lib/src/generated/element.dart ('K') | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698