The language specifies that any final field must have an explicit initializer in the constructor. So this generates a warning:
[warning] The final variable 'name' must be initialized (foo.dart, line 3, col 3)
Because, presumably, you forgot to initialize name and this class will never do anything useful.
But now consider this:
I still get a warning here. But now this code is deliberate, useful, and minimal. Adding an explicit name = null initializer to Foo.nameless() accomplishes nothing.
This came up in a real code review with a class that had two constructors. One was for an "undefined" state for the class where all of its fields were left null. To get the static warnings to shut up, the author had to add a painfully long list of " = null" initializers.
Does this warning actually prevent a common user error? Is it helpful in the non-false positive cases? If not, how about we just remove it?
If there is agreement that this isn't useful, I can write a little DEP for it. It would mean just removing this from the spec (section 10.6):
Each final instance variable f declared in the immediately enclosing class must have an initializer in k’s initializer list unless it has already been initialized by one of the following means: - Initialization at the declaration of f.
- Initialization by means of an initializing formal of k.
or a static warning occurs.
Thoughts?
– bob