-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Genercis can solve to Never
with final
/sealed
classes when it could never resolve
#56964
Comments
Summary: The issue reports that Dart's type inference for generics with |
This is working as intended. This means, in turn, that the actual argument
It sounds like this could only be done if static analysis would somehow decide that the type of But when there is a context type it is considered during inference, and this means that we do have those two subtype constraints where |
I'm aware. Edited above:
Say if the implementation of So in cases like this, I would only find out about the problem when running the code and getting to that point. Since we know that there is no valid return type that would be assignable for |
Just saw the edit. ;-) And the next comment.
Right, T baz<T extends num?>() => 0 as T;
void foo() {
String s = baz();
print('Hello, world!'); // Warning: Dead code!
} It might be useful to report on expressions of type Never doThrowSomething() => throw "Something";
int foo(int? i) => i == null ? doThrowSomething() : i; I think this illustrates that we can't simply decide that expressions should never have the type |
I would rely on the expected type (say
I saw that when creating the repro (swapped both lines on class A {
late final String str = baz();
} So fortunately I thought it was weird that there was no errors and added |
I don't believe that reporting an If we could get enough information out of type inference to know that the type This might even help in the second case, where an @stereotype441 Is there a way for the analyzer to get this information? |
I already had proposed something similar about casting unrelated types at dart-lang/linter#5062. |
If you write code like the following:
At
bar(0)
you get the following message:At
0
(insidebaz
) you get the following message:The argument type 'int' can't be assigned to the parameter type 'Never'.
In cases with
final
/sealed
types (likeString
andnum
) couldn't we calculate up toinvalid_assignment
instead of calculating the generics toNever
(we could still do that but it would be a bit counter intuitive)?Edit
Found this in a code that simply returned
T
without any parameter (it would look somewhere else for the value) and then the problem was happening inside when the return was happening.The text was updated successfully, but these errors were encountered: