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 error messages don't show '?'s inside function types. #39651

Closed
stereotype441 opened this issue Dec 4, 2019 · 2 comments
Closed

Analyzer error messages don't show '?'s inside function types. #39651

stereotype441 opened this issue Dec 4, 2019 · 2 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. NNBD Issues related to NNBD Release

Comments

@stereotype441
Copy link
Member

Consider the following code:

int? f(int i) => i;
void g(int Function(int?) callback) {}
main() {
  g(f);
}

Running this code through the analyzer with the NNBD experiment enabled produces the following unhelpful error messages:

  error • The argument type 'int Function(int)' can't be assigned to the parameter type 'int Function(int)'. • .../test.dart:4:5 • argument_type_not_assignable
  error • The function 'f' has type 'int Function(int)' that isn't of expected type 'int Function(int)'. This means its parameter or return type doesn't match what is expected. • .../test.dart:4:5 • invalid_cast_function

Setting aside the fact that there are two errors when there really should only be one, the error messages are unhelpful because they don't contain any ?s, so there's no way to see the actual problem.

I believe this bug only manifests when the types that are being printed are function types.

@stereotype441 stereotype441 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. NNBD Issues related to NNBD Release labels Dec 4, 2019
@stereotype441
Copy link
Member Author

@scheglov FYI

@scheglov scheglov self-assigned this Dec 9, 2019
@scheglov
Copy link
Contributor

scheglov commented Dec 9, 2019

https://dart-review.googlesource.com/c/sdk/+/127744

  error • The argument type 'int? Function(int)' can't be assigned to the parameter type 'int Function(int?)'. • /Users/scheglov/dart/test/bin/test.dart:4:5 • argument_type_not_assignable

The error from checker is not updated (not sure if we need, with DDC on the way out).

dart-bot pushed a commit that referenced this issue Dec 10, 2019
So, when we call DartType.getDisplayString() we know if the type
presentation should include nullability suffixes.

This fixes many, but not all places where we need to present types.
There are places where we don't go through ErrorReporter, but call
ErrorListener directly. I plan to replace all these with ErrorReporter.

R=brianwilkerson@google.com, paulberry@google.com

Bug: #39651
Change-Id: Ic77a556e7834d8f757c8b13eed37ed1d34f47348
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127744
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
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. NNBD Issues related to NNBD Release
Projects
None yet
Development

No branches or pull requests

2 participants