Skip to content
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

Analyzer's printing of function types will need to change to support nullability #35818

Closed
stereotype441 opened this issue Jan 30, 2019 · 4 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@stereotype441
Copy link
Member

The Dart syntax for function types takes the form returnType Function(parameters), but the analyzer reports function types (e.g. in diagnostic messages) using the terser syntax (parameters) → returnType. With the introduction of non-nullability, this will leads to an ambiguity: does (parameters) → returnType? mean that the return type is nullable, or that the entire function is nullable?

We should either adapt the display of function types to disambiguate with parentheses, or switch to using Function syntax.

@stereotype441 stereotype441 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels Jan 30, 2019
@bwilkerson
Copy link
Member

At the time that we chose that syntax, generic function types didn't exist. But now that it does, I think it would be better to switch to using the generic function syntax because I think it will be more familiar looking to more users.

@lrhn
Copy link
Member

lrhn commented Jan 31, 2019

I think we should use Function syntax for function types everywhere.
Even function.runtimeType.toString().

@stereotype441
Copy link
Member Author

At the time that we chose that syntax, generic function types didn't exist. But now that it does, I think it would be better to switch to using the generic function syntax because I think it will be more familiar looking to more users.

Agreed! I plan to do some investigation to see if the change would be breaking. (Technically it shouldn't be, because clients shouldn't rely on the behavior of FunctionType.toString(), but I wouldn't be surprised if some clients rely on it in unit tests.)

@stereotype441
Copy link
Member Author

Note that when we do this work we should eliminate the code duplication between FunctionTypeImpl.appendTo and _ElementWriter.writeType.

@scheglov scheglov self-assigned this Dec 5, 2019
dart-bot pushed a commit that referenced this issue Dec 5, 2019
R=brianwilkerson@google.com, paulberry@google.com

Bug: #35818
Change-Id: I9a86729ba48cf599c45afee2c7ba83f32ba3c30b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127445
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
@scheglov scheglov closed this as completed Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants