-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support @virtual
annotation on fields to allow field overrides in strong mode
#27384
Comments
Is there a reason why strong mode can't allow field overrides in the short term, rather than to introduce support that will require a breaking change to remove? |
We plan to have actual syntax, so no matter which annotation which choose now ( |
@leafpetersen also before we change the default, we should automated refactor our internal code base to seal-all-the-things. (edit: in other words, those fields are already safe to seal, so we might as well get the DDC size+perf benefit from that, rather than regress it.) |
note: also need to check that |
@virtual
annotation on fields to allow field overrides in strong mode@checked
annotation on fields to allow field overrides in strong mode
@checked
annotation on fields to allow field overrides in strong mode@virtual
annotation on fields to allow field overrides in strong mode
Ah, thanks! |
I tried removing One of the resulting errors was just a bug on our side. For two, arguably three, of the fields, adding For the remaining two cases, there's no way for the superclass to know that the subclass is going to want to override the field:
I wasn't able to test the actual analyzer with |
Would it work if you mark Imagine if you're designing a class in Java or C++ ... for which fields would you want to make a virtual get/set method? That tells you where to put the |
Just a short comment to be sure that it's clear:
Currently narrowing and overriding are two separate capabilities. |
@jmesserly But everything's virtual in dart. It's weird that (temporarily?) we'd be saying "everything is virtual except field getters and setters except if you say @virtual on the field". I wouldn't want to put I guess my question is, if this is just a temporary step along the way to making fields always virtual in strong mode, why not just make @leafpetersen Ah, ok. How will |
Sealed fields are still important for DDC users, and so we wish to maintain the distinction pending syntax for sealing.
You can place |
The current long term plan is to allow field overrides in strong mode with an opt out syntax for sealed fields. In the meantime, strong mode should support an opt-in for field overrides via an
@virtual
annotation.@sethladd @Hixie @abarth
The text was updated successfully, but these errors were encountered: