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

Side by Side Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 2340173002: address #25232 in strong mode (dart1 behavior unchanged) (Closed)
Patch Set: Merge remote-tracking branch 'origin/master' into 25232_strong_fix Created 4 years, 3 months 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.test.src.task.strong.checker_test; 5 library analyzer.test.src.task.strong.checker_test;
6 6
7 import 'package:test_reflective_loader/test_reflective_loader.dart'; 7 import 'package:test_reflective_loader/test_reflective_loader.dart';
8 8
9 import 'strong_test_helper.dart'; 9 import 'strong_test_helper.dart';
10 10
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 (/*info:DYNAMIC_INVOKE*/toStringClosure2()); 493 (/*info:DYNAMIC_INVOKE*/toStringClosure2());
494 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode; 494 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode;
495 495
496 baz().toString(); 496 baz().toString();
497 baz().hashCode; 497 baz().hashCode;
498 } 498 }
499 '''); 499 ''');
500 } 500 }
501 501
502 void test_covariantOverride() { 502 void test_covariantOverride() {
503 addFile(r''' 503 _addMetaLibrary();
504 library meta;
505 class _Checked { const _Checked(); }
506 const Object checked = const _Checked();
507 ''', name: '/meta.dart');
508
509 checkFile(r''' 504 checkFile(r'''
510 import 'meta.dart'; 505 import 'meta.dart';
511 class C { 506 class C {
512 num f(num x) => x; 507 num f(num x) => x;
513 } 508 }
514 class D extends C { 509 class D extends C {
515 int f(@checked int x) => x; 510 int f(@checked int x) => x;
516 } 511 }
517 class E extends D { 512 class E extends D {
518 int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x; 513 int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x;
(...skipping 12 matching lines...) Expand all
531 class F_error extends E { 526 class F_error extends E {
532 /*error:INVALID_METHOD_OVERRIDE*/int f(@checked double x) => 0; 527 /*error:INVALID_METHOD_OVERRIDE*/int f(@checked double x) => 0;
533 } 528 }
534 class G_error extends E implements D { 529 class G_error extends E implements D {
535 /*error:INVALID_METHOD_OVERRIDE*/int f(@checked double x) => 0; 530 /*error:INVALID_METHOD_OVERRIDE*/int f(@checked double x) => 0;
536 } 531 }
537 '''); 532 ''');
538 } 533 }
539 534
540 void test_covariantOverride_leastUpperBound() { 535 void test_covariantOverride_leastUpperBound() {
541 addFile(r''' 536 _addMetaLibrary();
542 library meta;
543 class _Checked { const _Checked(); }
544 const Object checked = const _Checked();
545 ''', name: '/meta.dart');
546
547 checkFile(r''' 537 checkFile(r'''
548 import "meta.dart"; 538 import "meta.dart";
549 abstract class Top {} 539 abstract class Top {}
550 abstract class Left implements Top {} 540 abstract class Left implements Top {}
551 abstract class Right implements Top {} 541 abstract class Right implements Top {}
552 abstract class Bottom implements Left, Right {} 542 abstract class Bottom implements Left, Right {}
553 543
554 abstract class TakesLeft { 544 abstract class TakesLeft {
555 m(Left x); 545 m(Left x);
556 } 546 }
557 abstract class TakesRight { 547 abstract class TakesRight {
558 m(Right x); 548 m(Right x);
559 } 549 }
560 abstract class TakesTop implements TakesLeft, TakesRight { 550 abstract class TakesTop implements TakesLeft, TakesRight {
561 m(Top x); // works today 551 m(Top x); // works today
562 } 552 }
563 abstract class TakesBottom implements TakesLeft, TakesRight { 553 abstract class TakesBottom implements TakesLeft, TakesRight {
564 // LUB(Left, Right) == Top, so this is an implicit cast from Top to Bottom. 554 // LUB(Left, Right) == Top, so this is an implicit cast from Top to Bottom.
565 m(@checked Bottom x); 555 m(@checked Bottom x);
566 } 556 }
567 '''); 557 ''');
568 } 558 }
569 559
570 void test_covariantOverride_markerIsInherited() { 560 void test_covariantOverride_markerIsInherited() {
571 addFile(r''' 561 _addMetaLibrary();
572 library meta;
573 class _Checked { const _Checked(); }
574 const Object checked = const _Checked();
575 ''', name: '/meta.dart');
576
577 checkFile(r''' 562 checkFile(r'''
578 import 'meta.dart'; 563 import 'meta.dart';
579 class C { 564 class C {
580 num f(@checked num x) => x; 565 num f(@checked num x) => x;
581 } 566 }
582 class D extends C { 567 class D extends C {
583 int f(int x) => x; 568 int f(int x) => x;
584 } 569 }
585 class E extends D { 570 class E extends D {
586 int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x; 571 int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x;
(...skipping 2521 matching lines...) Expand 10 before | Expand all | Expand 10 after
3108 n(B b); 3093 n(B b);
3109 } 3094 }
3110 abstract class D extends C { 3095 abstract class D extends C {
3111 /*error:INVALID_METHOD_OVERRIDE*/m(B b); 3096 /*error:INVALID_METHOD_OVERRIDE*/m(B b);
3112 n(A a); 3097 n(A a);
3113 } 3098 }
3114 '''); 3099 ''');
3115 check(implicitCasts: false); 3100 check(implicitCasts: false);
3116 } 3101 }
3117 3102
3103 void test_overrideNarrowsType_noDuplicateError() {
3104 // Regression test for https://github.com/dart-lang/sdk/issues/25232
3105 _addMetaLibrary();
3106 checkFile(r'''
3107 import 'meta.dart';
3108 abstract class A { void test(A arg) { } }
3109 abstract class B extends A {
3110 /*error:INVALID_METHOD_OVERRIDE*/void test(B arg) { }
3111 }
3112 abstract class X implements A { }
3113 class C extends B with X { }
3114
3115 // We treat "implements A" as asking for another check.
3116 // This feels inconsistent to me.
3117 class D /*error:INVALID_METHOD_OVERRIDE_FROM_BASE*/extends B implements A { }
3118 ''');
3119 }
3120
3121 void test_overrideNarrowsType_legalWithChecked() {
3122 // Regression test for https://github.com/dart-lang/sdk/issues/25232
3123 _addMetaLibrary();
3124 checkFile(r'''
3125 import 'meta.dart';
3126 abstract class A { void test(A arg) { } }
3127 abstract class B extends A { void test(@checked B arg) { } }
3128 abstract class X implements A { }
3129 class C extends B with X { }
3130 class D extends B implements A { }
3131 ''');
3132 }
3133
3118 void test_privateOverride() { 3134 void test_privateOverride() {
3119 addFile( 3135 addFile(
3120 ''' 3136 '''
3121 import 'main.dart' as main; 3137 import 'main.dart' as main;
3122 3138
3123 class Base { 3139 class Base {
3124 var f1; 3140 var f1;
3125 var _f2; 3141 var _f2;
3126 var _f3; 3142 var _f3;
3127 get _f4 => null; 3143 get _f4 => null;
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
3833 // Regression test for https://github.com/dart-lang/sdk/issues/25069 3849 // Regression test for https://github.com/dart-lang/sdk/issues/25069
3834 checkFile(''' 3850 checkFile('''
3835 typedef int Foo(); 3851 typedef int Foo();
3836 void foo() {} 3852 void foo() {}
3837 void main () { 3853 void main () {
3838 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); 3854 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo();
3839 } 3855 }
3840 '''); 3856 ''');
3841 } 3857 }
3842 } 3858 }
3859
3860 void _addMetaLibrary() {
3861 addFile(r'''
3862 library meta;
3863 class _Checked { const _Checked(); }
3864 const Object checked = const _Checked();
3865 ''', name: '/meta.dart');
3866 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698