Open FMorschel opened 1 year ago
The argument_type_not_assignable
diagnostic isn't a lint, it's a compilation error that means that your code won't compile or run.
The problem is that the conditional expression produces a value whose static type is the least upper bound of the types of the then
and else
expressions (void Function([String?])
and void Function()
respectively. Because those signatures don't match, the least upper bound is Function
, which really isn't assignable to void Function(String)
. You could correct the issue by writing
fn(
parameter: test ? function2 : ([String? _]) => callback(),
);
But there is a bug here, in that unnecessary_lambdas
shouldn't have beed produced in this case because the type of the closure isn't the same as the type of the tear-off.
Understood.
Though I still don't follow why the (_)
on (_) => callback()
is not parsed as String
when it is placed as a function parameter.
You're right, the type of the parameter is inferred to be String
, but the least upper bound of void Function([String?])
and void Function(String)
is still be Function
because of the difference in nullability.
Thank you for the explanation!
Yes. Thank you both!
You're right, the type of the parameter is inferred to be
String
, but the least upper bound ofvoid Function([String?])
andvoid Function(String)
is still beFunction
because of the difference in nullability.
@bwilkerson, is there any documentation on this? I want to understand better, why it couldn't interfere void Function(String)
since both could be used as such.
This comment in the language tracker may be your best source of documentation, and the current state of things.
Describe the issue I had a tear-off on my parameter, but I had to change it with a ternary operator. That triggered this false positive.
To Reproduce
argument_type_not_assignable
triggering on:When I "solved" that with:
Previously I had (and it was working):
Expected behavior
argument_type_not_assignable
not triggering when that solvesunnecessary_lambdas
or stoppingunnecessary_lambdas
from triggering.