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

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

Issue 700923002: Warn when implicit default value overrides explicit one that differs. (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
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | tests/co19/co19-analyzer2.status » ('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) 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/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:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 int m() { return 0; } 1702 int m() { return 0; }
1703 } 1703 }
1704 class B extends A { 1704 class B extends A {
1705 void m() {} 1705 void m() {}
1706 }'''); 1706 }''');
1707 resolve(source); 1707 resolve(source);
1708 assertErrors(source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE] ); 1708 assertErrors(source, [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE] );
1709 verify([source]); 1709 verify([source]);
1710 } 1710 }
1711 1711
1712 void test_invalidOverride_defaultOverridesNonDefault() {
1713 // If the base class provided an explicit value for a default parameter,
1714 // then it is a static warning for the derived class to provide a different
1715 // value, even if implicitly.
1716 Source source = addSource(r'''
1717 class A {
1718 foo([x = 1]) {}
1719 }
1720 class B extends A {
1721 foo([x]) {}
1722 }
1723 ''');
1724 resolve(source);
1725 assertErrors(source, [
1726 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL]) ;
1727 verify([source]);
1728 }
1729
1730 void test_invalidOverride_defaultOverridesNonDefault_named() {
1731 // If the base class provided an explicit value for a default parameter,
1732 // then it is a static warning for the derived class to provide a different
1733 // value, even if implicitly.
1734 Source source = addSource(r'''
1735 class A {
1736 foo({x: 1}) {}
1737 }
1738 class B extends A {
1739 foo({x}) {}
1740 }
1741 ''');
1742 resolve(source);
1743 assertErrors(source, [
1744 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
1745 verify([source]);
1746 }
1747
1748 void test_invalidOverride_defaultOverridesNonDefaultNull() {
Brian Wilkerson 2014/11/04 18:46:42 I'm not sure whether we want to continue, but the
1749 // If the base class provided an explicit null value for a default
1750 // parameter, then it is ok for the derived class to let the default value
1751 // be implicit, because the implicit default value of null matches the
1752 // explicit default value of null.
1753 Source source = addSource(r'''
1754 class A {
1755 foo([x = null]) {}
1756 }
1757 class B extends A {
1758 foo([x]) {}
1759 }
1760 ''');
1761 resolve(source);
1762 assertNoErrors(source);
scheglov 2014/11/04 18:43:20 Test cases without errors should be added to NonEr
1763 verify([source]);
1764 }
1765
1766 void test_invalidOverride_defaultOverridesNonDefaultNull_named() {
1767 // If the base class provided an explicit null value for a default
1768 // parameter, then it is ok for the derived class to let the default value
1769 // be implicit, because the implicit default value of null matches the
1770 // explicit default value of null.
1771 Source source = addSource(r'''
1772 class A {
1773 foo({x: null}) {}
1774 }
1775 class B extends A {
1776 foo({x}) {}
1777 }
1778 ''');
1779 resolve(source);
1780 assertNoErrors(source);
1781 verify([source]);
1782 }
1783
1784 void test_invalidOverride_nonDefaultOverridesDefault() {
1785 // If the base class lets the default parameter be implicit, then it is ok
1786 // for the derived class to provide an explicit default value, even if it's
1787 // not null.
1788 Source source = addSource(r'''
1789 class A {
1790 foo([x]) {}
1791 }
1792 class B extends A {
1793 foo([x = 1]) {}
1794 }
1795 ''');
1796 resolve(source);
1797 assertNoErrors(source);
1798 verify([source]);
1799 }
1800
1801 void test_invalidOverride_nonDefaultOverridesDefault_named() {
1802 // If the base class lets the default parameter be implicit, then it is ok
1803 // for the derived class to provide an explicit default value, even if it's
1804 // not null.
1805 Source source = addSource(r'''
1806 class A {
1807 foo({x}) {}
1808 }
1809 class B extends A {
1810 foo({x: 1}) {}
1811 }
1812 ''');
1813 resolve(source);
1814 assertNoErrors(source);
1815 verify([source]);
1816 }
1817
1712 void test_invalidOverrideDifferentDefaultValues_named() { 1818 void test_invalidOverrideDifferentDefaultValues_named() {
1713 Source source = addSource(r''' 1819 Source source = addSource(r'''
1714 class A { 1820 class A {
1715 m({int p : 0}) {} 1821 m({int p : 0}) {}
1716 } 1822 }
1717 class B extends A { 1823 class B extends A {
1718 m({int p : 1}) {} 1824 m({int p : 1}) {}
1719 }'''); 1825 }''');
1720 resolve(source); 1826 resolve(source);
1721 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_V ALUES_NAMED]); 1827 assertErrors(source, [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_V ALUES_NAMED]);
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
3137 }'''); 3243 }''');
3138 resolve(source); 3244 resolve(source);
3139 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); 3245 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]);
3140 } 3246 }
3141 } 3247 }
3142 3248
3143 main() { 3249 main() {
3144 groupSep = ' | '; 3250 groupSep = ' | ';
3145 runReflectiveTests(StaticWarningCodeTest); 3251 runReflectiveTests(StaticWarningCodeTest);
3146 } 3252 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | tests/co19/co19-analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698