-
Notifications
You must be signed in to change notification settings - Fork 209
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
Should we allow eliding final
on field declarations in enums and inline classes?
#3171
Comments
There is a difference, a level of indirection, betwen the parameters of the primary constructor and the fields they imply (and the actual constuctor and constructor parameters that they imply too). So I'm not worried that class const Point(int x, int y); doesn't say I'm more worried about reading class Point {
int x, y;
const Point(this.x, this.y);
} and not being able to see that That is allowing you to omit Let's assume that we do want to allow omitting I'll assume we don't allow Where would omitting
This feels like a sliding scale from obvious to obscure. There is an underlying concept of "must allow being constant" which implies that all fields must be final, and final field initialziers must be constant. Currently that only affects The clear cut-off points on the scale are:
I worry that allowing classes-with-const-constructor to omit So if we were to do this, I'd only allow it if the declaration is marked as intending to be constant, which means being an enum or inline class, or being marked with class const Foo { ... } You can then remove the last constant constructor (and maybe get a hint that you did so), but the constraint that all fields must be final and field initilizers must be constant is still there, and And if we do go this way, I'd make enum generative constructors not have to say |
I'd refer to the localized nature of the We have prior art in the rule that allows As soon as we allow these syntactic elements to be separated by an unlimited number of tokens it is going to be possible to read |
The primary constructors proposal (#3023) says:
I'm a little worried about the implicit magic here, but I think the argument makes sense. The brevity is certainly nice.
However, I find the inconsistency with field declarations worrisome. If we really think it makes sense to elide
final
on parameters in primary constructors on inline classes, shouldn't also allow elidingfinal
on field declarations in inline classes and enums too? The argument seems to equally well to them.Why not let you write:
Whichever way we decide to go, I think primary constructors should probably be consistent with field declarations.
The text was updated successfully, but these errors were encountered: