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

Runtime error messages refer to Function types differently than code #48826

Open
jamesderlin opened this issue Apr 16, 2022 · 0 comments
Open
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P3 A lower priority bug or feature request

Comments

@jamesderlin
Copy link
Contributor

jamesderlin commented Apr 16, 2022

Running the code:

void main() {
  void Function(int) f = (() => 42) as void Function(int);
}

generates an error:

type '() => int' is not a subtype of type '(int) => void' in type cast

I think it would be better if the error message used Dart's normal syntax for Function types. That is, I think the error message would be better as:

type 'int Function()' is not a subtype of type 'void Function(int)` in type cast.

Note that the analyzer already does that. If I remove the cast, the analyzer reports:

A value of type 'void Function()' can't be
assigned to a variable of type 'void Function(int)'. Try changing
the type of the variable, or casting the right-hand type to 'void
Function(int)'. • invalid_assignment

(The example above is contrived (people should not be performing explicit casts on Function objects in practice), but that form of error is encountered in the wild (often with a combination of generic classes, callbacks, and accidentally omitted type parameters).)

@keertip keertip added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Apr 18, 2022
@a-siva a-siva added the P3 A lower priority bug or feature request label Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants