-
Notifications
You must be signed in to change notification settings - Fork 118
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
Add checks for 'late' initialized finals in dartdoc and clean up #2069
Conversation
Field b = c.allFields.firstWhere((f) => f.name == 'b'); | ||
Field cField = c.allFields.firstWhere((f) => f.name == 'cField'); | ||
Field dField = c.allFields.firstWhere((f) => f.name == 'dField'); | ||
// If nnbd isn't enabled, fields named 'late' come back from the analyzer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it useful to test for late
when it is invalid to use?
I expected to see a NNBD enabled test, with late
displayed as a modifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I this the test is what you expected, and that this is just ensuring that the library was analyzed correctly as being opted in. The comment indicates what analyzer would have produced if NNBD were not enabled, and hence what's being tested for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the late initialization of a field matters enough to mention it from the perspective of the API of a class -- though even as I say that I'm starting to wonder if that's true. I think it would usually be bad design to declare as a final field something you wanted users of the class to initialize externally, but I can think of some cases where people might desire that. My current thought is to tell users who do that to explicitly describe what's necessary in the doc for the field.
Field b = c.allFields.firstWhere((f) => f.name == 'b'); | ||
Field cField = c.allFields.firstWhere((f) => f.name == 'cField'); | ||
Field dField = c.allFields.firstWhere((f) => f.name == 'dField'); | ||
// If nnbd isn't enabled, fields named 'late' come back from the analyzer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I this the test is what you expected, and that this is just ensuring that the library was analyzed correctly as being opted in. The comment indicates what analyzer would have produced if NNBD were not enabled, and hence what's being tested for.
This lays groundwork for NNBD work in dartdoc. Basically this tests that switching on nnbd is possible and we generate reasonable output for a trivial case.
Screenshot: