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

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

Issue 1042133002: Generate warnings for assignment to a type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | 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.static_warning_code_test; 5 library engine.static_warning_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/source_io.dart'; 8 import 'package:analyzer/src/generated/source_io.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 A(String p) {} 591 A(String p) {}
592 } 592 }
593 main() { 593 main() {
594 new A(42); 594 new A(42);
595 }'''); 595 }''');
596 resolve(source); 596 resolve(source);
597 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 597 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
598 verify([source]); 598 verify([source]);
599 } 599 }
600 600
601 void test_assignmentToClass() {
602 Source source = addSource('''
603 class C {}
604 main() {
605 C = null;
606 }
607 ''');
608 resolve(source);
609 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
610 }
611
601 void test_assignmentToConst_instanceVariable() { 612 void test_assignmentToConst_instanceVariable() {
602 Source source = addSource(r''' 613 Source source = addSource(r'''
603 class A { 614 class A {
604 static const v = 0; 615 static const v = 0;
605 } 616 }
606 f() { 617 f() {
607 A.v = 1; 618 A.v = 1;
608 }'''); 619 }''');
609 resolve(source); 620 resolve(source);
610 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); 621 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]);
(...skipping 28 matching lines...) Expand all
639 Source source = addSource(r''' 650 Source source = addSource(r'''
640 f() { 651 f() {
641 const x = 0; 652 const x = 0;
642 x += 1; 653 x += 1;
643 }'''); 654 }''');
644 resolve(source); 655 resolve(source);
645 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]); 656 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_CONST]);
646 verify([source]); 657 verify([source]);
647 } 658 }
648 659
660 void test_assignmentToEnumType() {
661 Source source = addSource('''
662 enum E { e }
663 main() {
664 E = null;
665 }
666 ''');
667 resolve(source);
668 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
669 }
670
649 void test_assignmentToFinal_instanceVariable() { 671 void test_assignmentToFinal_instanceVariable() {
650 Source source = addSource(r''' 672 Source source = addSource(r'''
651 class A { 673 class A {
652 final v = 0; 674 final v = 0;
653 } 675 }
654 f() { 676 f() {
655 A a = new A(); 677 A a = new A();
656 a.v = 1; 678 a.v = 1;
657 }'''); 679 }''');
658 resolve(source); 680 resolve(source);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 m() {} 840 m() {}
819 } 841 }
820 f(A a) { 842 f(A a) {
821 a.m = () {}; 843 a.m = () {};
822 }'''); 844 }''');
823 resolve(source); 845 resolve(source);
824 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_METHOD]); 846 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_METHOD]);
825 verify([source]); 847 verify([source]);
826 } 848 }
827 849
850 void test_assignmentToTypedef() {
851 Source source = addSource('''
852 typedef void F();
853 main() {
854 F = null;
855 }
856 ''');
857 resolve(source);
858 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
859 }
860
861 void test_assignmentToTypeParameter() {
862 Source source = addSource('''
863 class C<T> {
864 f() {
865 T = null;
866 }
867 }
868 ''');
869 resolve(source);
870 assertErrors(source, [StaticWarningCode.ASSIGNMENT_TO_TYPE]);
871 }
872
828 void test_caseBlockNotTerminated() { 873 void test_caseBlockNotTerminated() {
829 Source source = addSource(r''' 874 Source source = addSource(r'''
830 f(int p) { 875 f(int p) {
831 switch (p) { 876 switch (p) {
832 case 0: 877 case 0:
833 f(p); 878 f(p);
834 case 1: 879 case 1:
835 break; 880 break;
836 } 881 }
837 }'''); 882 }''');
(...skipping 2645 matching lines...) Expand 10 before | Expand all | Expand 10 after
3483 3528
3484 void test_voidReturnForGetter() { 3529 void test_voidReturnForGetter() {
3485 Source source = addSource(r''' 3530 Source source = addSource(r'''
3486 class S { 3531 class S {
3487 void get value {} 3532 void get value {}
3488 }'''); 3533 }''');
3489 resolve(source); 3534 resolve(source);
3490 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); 3535 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]);
3491 } 3536 }
3492 } 3537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698