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

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

Issue 2352433002: support `@virtual` fields, fix #27384 (Closed)
Patch Set: 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/task/strong_mode.dart ('k') | pkg/meta/CHANGELOG.md » ('j') | 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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 533 }
534 534
535 void test_covariantOverride_fields() { 535 void test_covariantOverride_fields() {
536 _addMetaLibrary(); 536 _addMetaLibrary();
537 checkFile(r''' 537 checkFile(r'''
538 import 'meta.dart'; 538 import 'meta.dart';
539 class A { 539 class A {
540 get foo => ''; 540 get foo => '';
541 set foo(_) {} 541 set foo(_) {}
542 } 542 }
543
543 class B extends A { 544 class B extends A {
544 @checked int foo; 545 @checked num foo;
546 }
547 class C extends A {
548 @checked @virtual num foo;
549 }
550 class D extends C {
551 @virtual int foo;
552 }
553 class E extends D {
554 @virtual /*error:INVALID_METHOD_OVERRIDE*/num foo;
545 } 555 }
546 '''); 556 ''');
547 } 557 }
548 558
549 void test_covariantOverride_leastUpperBound() { 559 void test_covariantOverride_leastUpperBound() {
550 _addMetaLibrary(); 560 _addMetaLibrary();
551 checkFile(r''' 561 checkFile(r'''
552 import "meta.dart"; 562 import "meta.dart";
553 abstract class Top {} 563 abstract class Top {}
554 abstract class Left implements Top {} 564 abstract class Left implements Top {}
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 /*error:INVALID_FIELD_OVERRIDE, error:INVALID_METHOD_OVERRIDE*/final ToVoid<dy namic> g = null; 755 /*error:INVALID_FIELD_OVERRIDE, error:INVALID_METHOD_OVERRIDE*/final ToVoid<dy namic> g = null;
746 } 756 }
747 757
748 class H implements F { 758 class H implements F {
749 final ToVoid<int> f = null; 759 final ToVoid<int> f = null;
750 /*error:INVALID_METHOD_OVERRIDE*/final ToVoid<dynamic> g = null; 760 /*error:INVALID_METHOD_OVERRIDE*/final ToVoid<dynamic> g = null;
751 } 761 }
752 '''); 762 ''');
753 } 763 }
754 764
765 void test_fieldOverride_virtual() {
766 _addMetaLibrary();
767 checkFile(r'''
768 import 'meta.dart';
769 class C {
770 @virtual int x;
771 }
772 class OverrideGetter extends C {
773 int get x => 42;
774 }
775 class OverrideSetter extends C {
776 set x(int v) {}
777 }
778 class OverrideBoth extends C {
779 int get x => 42;
780 set x(int v) {}
781 }
782 class OverrideWithField extends C {
783 int x;
784
785 // expose the hidden storage slot
786 int get superX => super.x;
787 set superX(int v) { super.x = v; }
788 }
789 class VirtualNotInherited extends OverrideWithField {
790 /*error:INVALID_FIELD_OVERRIDE*/int x;
791 }
792 ''');
793 }
794
755 void test_fieldSetterOverride() { 795 void test_fieldSetterOverride() {
756 checkFile(''' 796 checkFile('''
757 class A {} 797 class A {}
758 class B extends A {} 798 class B extends A {}
759 class C extends B {} 799 class C extends B {}
760 800
761 class Base { 801 class Base {
762 B f1; 802 B f1;
763 B f2; 803 B f2;
764 B f3; 804 B f3;
(...skipping 3104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3869 } 3909 }
3870 '''); 3910 ''');
3871 } 3911 }
3872 } 3912 }
3873 3913
3874 void _addMetaLibrary() { 3914 void _addMetaLibrary() {
3875 addFile(r''' 3915 addFile(r'''
3876 library meta; 3916 library meta;
3877 class _Checked { const _Checked(); } 3917 class _Checked { const _Checked(); }
3878 const Object checked = const _Checked(); 3918 const Object checked = const _Checked();
3919
3920 class _Virtual { const _Virtual(); }
3921 const Object virtual = const _Virtual();
3879 ''', name: '/meta.dart'); 3922 ''', name: '/meta.dart');
3880 } 3923 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/strong_mode.dart ('k') | pkg/meta/CHANGELOG.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698