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

Generic function can't be passed as an argument #55770

Open
seha-bot opened this issue May 18, 2024 · 2 comments
Open

Generic function can't be passed as an argument #55770

seha-bot opened this issue May 18, 2024 · 2 comments
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@seha-bot
Copy link

This code compiles fine, but the analyser gives an error:

The argument type 'List<T> Function<T>(T)' can't be assigned to the parameter type 'List<Z0> Function<F>(F)'. 

Code:

List<T> toList<T>(T x) => [x];

R calc<R>(R Function<F>(F) f) {
  return f(0);
}

void main() {
  final res = calc(toList);
  print(res);
}
@lrhn
Copy link
Member

lrhn commented May 18, 2024

Seems like an inference difference.

If the type argument to calc in main is inferred as List<TopType>, then toList should be a valid argument.
It seems the analyzer infers it to a type variable, not its upper bound.

@eernstg
Copy link
Member

eernstg commented May 19, 2024

This could be a duplicate of #55644. Note that the type variable Z0 does not exist in the program, which means that it should never leak and occur as part of a result provided by type inference.

@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 19, 2024
@scheglov scheglov added P3 A lower priority bug or feature request analyzer-spec Issues with the analyzer's implementation of the language spec labels May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants