-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Comments
@leafpetersen Are the tests above valid? (I'm guessing the answer is "yes", but would appreciate the confirmation anyway.) |
Apparently, this error checking was part of ErrorVerifier and removed in Remove spec mode support from ErrorVerifier. Thanks to @bwilkerson for tracking this down. |
Yes, they look right to me. cc @lrhn |
I agree that the test should give compile-time errors with the current specification.
|
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. |
CFE also does not report these as errors, it will be breaking to change this to an error. |
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 |
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. |
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. |
…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>
I'm reverting 6699384 because of failures in Flutter (https://dart-review.googlesource.com/c/sdk/+/91360). Let's discuss with @leafpetersen today. |
…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>
We should just fix the instances that broke in Flutter to use the same default. |
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. |
Sometimes. Sometimes it will not, because the value is an |
Yes, Flutter will still break if they're warnings. |
…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>
…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
…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
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:
The text was updated successfully, but these errors were encountered: