Skip to content

CFE does not support instantiation of function .call tearoff #45857

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

Closed
stereotype441 opened this issue Apr 28, 2021 · 1 comment
Closed

CFE does not support instantiation of function .call tearoff #45857

stereotype441 opened this issue Apr 28, 2021 · 1 comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@stereotype441
Copy link
Member

The following code is accepted by the analyzer but rejected by the CFE:

main() {
  S Function(S) specialize<S>(T Function<T>(T) f) => f.call;
  X id<X>(X value) => value;
  int Function(int) intId = specialize(id);
  X defaulter<X>(X? value, [X? defaultValue]) => value ?? defaultValue ?? (throw ArgumentError("no default"));
  intId = specialize(defaulter);
  print(intId.runtimeType);
}

The CFE says:

../../tmp/proj/test.dart:3:57: Error: A value of type 'T Function<T>(T)' can't be returned from a function with return type 'int Function(int)'.
  int Function(int) specialize(T Function<T>(T) f) => f.call;

After experimenting a bit, I think that the CFE only allows generic instantiation of .call if .call resolves to a method on an actual class; if it resolves to the implicit .call of a function type, that's not supported.

The language team is currently having a discussion about related topics at dart-lang/language#1604, and it's not yet clear to me what the best fix is. So for now I'm assigning this issue to area-language. We can re-assign it to area-front-end or area-analyzer once we decide what we want the correct behavior to be.

@stereotype441 stereotype441 added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Apr 28, 2021
@stereotype441
Copy link
Member Author

Duplicate of #45936

@stereotype441 stereotype441 marked this as a duplicate of #45936 May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

1 participant