Chromium Code Reviews| 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 { |