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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | tests/co19/co19-analyzer2.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/static_warning_code_test.dart
diff --git a/pkg/analyzer/test/generated/static_warning_code_test.dart b/pkg/analyzer/test/generated/static_warning_code_test.dart
index 2c779c564928dbf413af12e2660b753ecc959f7e..532450e1b5bdd066a45a64d22dcd111f16840470 100644
--- a/pkg/analyzer/test/generated/static_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_warning_code_test.dart
@@ -1709,6 +1709,112 @@ class B extends A {
verify([source]);
}
+ void test_invalidOverride_defaultOverridesNonDefault() {
+ // If the base class provided an explicit value for a default parameter,
+ // then it is a static warning for the derived class to provide a different
+ // value, even if implicitly.
+ Source source = addSource(r'''
+class A {
+ foo([x = 1]) {}
+}
+class B extends A {
+ foo([x]) {}
+}
+''');
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL]);
+ verify([source]);
+ }
+
+ void test_invalidOverride_defaultOverridesNonDefault_named() {
+ // If the base class provided an explicit value for a default parameter,
+ // then it is a static warning for the derived class to provide a different
+ // value, even if implicitly.
+ Source source = addSource(r'''
+class A {
+ foo({x: 1}) {}
+}
+class B extends A {
+ foo({x}) {}
+}
+''');
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED]);
+ verify([source]);
+ }
+
+ void test_invalidOverride_defaultOverridesNonDefaultNull() {
Brian Wilkerson 2014/11/04 18:46:42 I'm not sure whether we want to continue, but the
+ // If the base class provided an explicit null value for a default
+ // parameter, then it is ok for the derived class to let the default value
+ // be implicit, because the implicit default value of null matches the
+ // explicit default value of null.
+ Source source = addSource(r'''
+class A {
+ foo([x = null]) {}
+}
+class B extends A {
+ foo([x]) {}
+}
+''');
+ resolve(source);
+ assertNoErrors(source);
scheglov 2014/11/04 18:43:20 Test cases without errors should be added to NonEr
+ verify([source]);
+ }
+
+ void test_invalidOverride_defaultOverridesNonDefaultNull_named() {
+ // If the base class provided an explicit null value for a default
+ // parameter, then it is ok for the derived class to let the default value
+ // be implicit, because the implicit default value of null matches the
+ // explicit default value of null.
+ Source source = addSource(r'''
+class A {
+ foo({x: null}) {}
+}
+class B extends A {
+ foo({x}) {}
+}
+''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_invalidOverride_nonDefaultOverridesDefault() {
+ // If the base class lets the default parameter be implicit, then it is ok
+ // for the derived class to provide an explicit default value, even if it's
+ // not null.
+ Source source = addSource(r'''
+class A {
+ foo([x]) {}
+}
+class B extends A {
+ foo([x = 1]) {}
+}
+''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_invalidOverride_nonDefaultOverridesDefault_named() {
+ // If the base class lets the default parameter be implicit, then it is ok
+ // for the derived class to provide an explicit default value, even if it's
+ // not null.
+ Source source = addSource(r'''
+class A {
+ foo({x}) {}
+}
+class B extends A {
+ foo({x: 1}) {}
+}
+''');
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
void test_invalidOverrideDifferentDefaultValues_named() {
Source source = addSource(r'''
class A {
« 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