Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An overriding method can't specify a different default value #34437

Closed
7 tasks
danrubel opened this issue Sep 11, 2018 · 17 comments
Closed
7 tasks

An overriding method can't specify a different default value #34437

danrubel opened this issue Sep 11, 2018 · 17 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@danrubel
Copy link

The failing co19_2 tests appear to be due to missing constant evaluation or error checking after constant evaluation should be performed. I don't think that this should occur in the fasta parser or in AstBuilder, but if so, feel free to assign it to me and I'll fix.

tests/co19_2/co19_2-analyzer.status:

  • Language/Classes/Abstract_Instance_Members/override_default_value_t01
  • Language/Classes/Abstract_Instance_Members/override_default_value_t02
  • Language/Classes/Abstract_Instance_Members/override_default_value_t03
  • Language/Classes/Abstract_Instance_Members/override_default_value_t04
  • Language/Classes/Abstract_Instance_Members/override_default_value_t05
  • /Language/Classes/Instance_Methods/override_different_default_values_t01
  • /Language/Classes/Instance_Methods/override_different_default_values_t02
@danrubel danrubel added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Sep 11, 2018
@bwilkerson
Copy link
Member

@leafpetersen Are the tests above valid? (I'm guessing the answer is "yes", but would appreciate the confirmation anyway.)

@danrubel
Copy link
Author

Apparently, this error checking was part of ErrorVerifier and removed in Remove spec mode support from ErrorVerifier. Thanks to @bwilkerson for tracking this down.

@leafpetersen
Copy link
Member

Yes, they look right to me.

cc @lrhn

@lrhn
Copy link
Member

lrhn commented Sep 12, 2018

I agree that the test should give compile-time errors with the current specification.

It is a compile-time error if an instance method $m_1$ overrides an instance member $m_2$, the signature of $m_2$ explicitly specifies a default value for a formal parameter $p$, and the signature of $m_1$ implies a different default value for $p$.

@bwilkerson
Copy link
Member

Thanks!

Just to clarify, the error reporting wasn't removed in that CL. The code that referenced the error code was removed, but the removed wasn't being run when strong mode was enabled. The removed code indicates that this error was being generated elsewhere, but I have not been able to find where that was suppose to be happening (it wasn't using this error code).

What I can tell you is that these tests were marked as failing when the co19_2 tests were created on Feb 1, 2018 (https://dart-review.googlesource.com/37743). I suspect that this error was accidentally disabled at some point during the development of strong mode. In any case, it's been broken for at least 7 months.

@natebosch
Copy link
Member

CFE also does not report these as errors, it will be breaking to change this to an error.

@lrhn
Copy link
Member

lrhn commented Sep 14, 2018

If no compiler implements the restriction, and it'll be a compile-time error to re-introduce it, we may want to consider just dropping the restriction.

It's not required for soundness, and it means that a subclass can't just drop the default value and use param ??= defaultValue; in code instead, even if that actually handles explicit null arguments better.
Or a sub-class can't use a more specialized default value (say const ColorPoint(0, 0, Color.black) instead of const Point(0, 0), which makes sense for covariant parameters).

@leafpetersen
Copy link
Member

We discussed this today in the language meeting. We will demote this to a warning for the time being, and consider changing it to an error (breaking change) in the future. So the resolution of this bug is to add this back in as a warning.

@stereotype441
Copy link
Member

Escalating to P1 since the front end has this bug too, so users are in danger of violating this warning by accident. Note that prior to landing a fix for this bug we should check that no internal code will be broken by the change.

@stereotype441 stereotype441 added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Dec 14, 2018
@scheglov scheglov self-assigned this Jan 25, 2019
@scheglov
Copy link
Contributor

dart-bot pushed a commit that referenced this issue Jan 26, 2019
…sses should have the same default values as overridden.

R=brianwilkerson@google.com, paulberry@google.com

Bug: #34437
Change-Id: Ic54d2e074bc764376f970c9c29ba260e7a373d93
Reviewed-on: https://dart-review.googlesource.com/c/91170
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
@stereotype441
Copy link
Member

I'm reverting 6699384 because of failures in Flutter (https://dart-review.googlesource.com/c/sdk/+/91360). Let's discuss with @leafpetersen today.

@stereotype441 stereotype441 reopened this Jan 28, 2019
dart-bot pushed a commit that referenced this issue Jan 28, 2019
…ived classes should have the same default values as overridden."

This reverts commit 6699384.

Reason for revert: Breakages in Flutter - see https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket.appspot.com/8923238548150736816/+/steps/analyze_flutter/0/stdout

Original change's description:
> Issue 34437. Restore checking that optional parameters in derived classes should have the same default values as overridden.
> 
> R=​brianwilkerson@google.com, paulberry@google.com
> 
> Bug: #34437
> Change-Id: Ic54d2e074bc764376f970c9c29ba260e7a373d93
> Reviewed-on: https://dart-review.googlesource.com/c/91170
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>

TBR=paulberry@google.com,scheglov@google.com,brianwilkerson@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: #34437
Change-Id: I07c96c8131c16b2748a403f38d5f15b814131c63
Reviewed-on: https://dart-review.googlesource.com/c/91360
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
@leafpetersen
Copy link
Member

cc @tvolkert @Hixie

This is currently a warning, and so users are free to ignore it. I'd suggest that we send a PR to flutter globally suppressing this warning, they are then free to re-enable it and fix up their code if they want the warning, and continue to ignore it if not.

@tvolkert
Copy link
Contributor

We should just fix the instances that broke in Flutter to use the same default.

@Hixie
Copy link
Contributor

Hixie commented Jan 28, 2019

It would be much easier to determine whether the new warnings are valid or false positives if the error message told you what the superclass' and subclass' defaults are.

@scheglov
Copy link
Contributor

Sometimes. Sometimes it will not, because the value is an int, and what you really want is to reference a constant by name.

@scheglov
Copy link
Contributor

@tvolkert @Hixie If these problems are warnings, will they still break Flutter?

I have a PR for Flutter, but it changes default values to make them the same as inherited, but different than they were. This might be a reason that build fails.

@tvolkert
Copy link
Contributor

Yes, Flutter will still break if they're warnings.

dart-bot pushed a commit that referenced this issue Jan 29, 2019
…sses should have the same default values as overridden.

Downgrade INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED and INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL to warnings.

Bug: #34437
Change-Id: I4399839e04135a5d9a557c0ab06f319d9759af23
Reviewed-on: https://dart-review.googlesource.com/c/91460
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
nshahan pushed a commit to angulardart/angular_components that referenced this issue Feb 13, 2019
…er default values.

More correct checking of invalid override method parameter default values recently landed in the SDK [1]. The changes fit a few shapes, given a method `m1`, which overrides a method `m2`:

* If `m2` has a parameter `p` with a default value, but the parameter `p` on
  `m1` does _not_ have a default value, I have added a default value.
* If `m2` has a parameter `p` with a default value, and the parameter `p` on
  `m1` has a _different_ default value, I have either:
  * changed the default value on `m1` to equal that on `m2`, or
  * removed the default value on `m2`, instead assigning it with `??=` as the
    first statement in the method body.

[1] dart-lang/sdk#34437

PiperOrigin-RevId: 233486440
nshahan pushed a commit to angulardart/angular_components that referenced this issue Feb 14, 2019
…er default values.

More correct checking of invalid override method parameter default values recently landed in the SDK [1]. The changes fit a few shapes, given a method `m1`, which overrides a method `m2`:

* If `m2` has a parameter `p` with a default value, but the parameter `p` on
  `m1` does _not_ have a default value, I have added a default value.
* If `m2` has a parameter `p` with a default value, and the parameter `p` on
  `m1` has a _different_ default value, I have either:
  * changed the default value on `m1` to equal that on `m2`, or
  * removed the default value on `m2`, instead assigning it with `??=` as the
    first statement in the method body.

[1] dart-lang/sdk#34437

PiperOrigin-RevId: 233486440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

9 participants