Closed
Description
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.