-
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
"this is Foo ? this : null" => "Type check failed: ... is not of type Foo" #25260
Comments
This is a case where Dart's internal type promotion fails. The In Dart, you can't cast an
|
What would that take? language fix? |
@lrhn The solution I went with was It'd be interesting to allow promotion to tag variables with multiple disjoint types. (In general it would be great to have that in the language, too, i.e. union types. Presumably if we had union types it would become easier to have promotion promote to union types too!) I don't know how often we hit this exact case, but I can imagine it happening more in the future, certainly. It's a useful pattern. Anyway, thanks for the explanation! |
Yes. We only do type propagation for variables. We could treat |
Technically (obXkcd) that would be intersection types, which is the dual of union types. A union type is a type that allows either of the types. Here we want to know that the actual type is all of the types - it's both |
The question in this issue seems to have been adequately answered. |
@askeksa-google how so? is it fixed? |
I understand the discussion here as describing two reasons why the example does not work with the Dart type promotion. It is not clear whether this is a feature request, and if it is, whether it is about type promotion on If you think it is still relevant to track either or both of these feature requests, please re-open the issue or file new ones. In any case the two independent issues should be clearly distinguished between. |
The issue is still real. Whether it's relevant to track is up to you. |
Analyze:
Gives these two errors (or only the second when you turn off strong mode):
...but you can statically determine that this code is type-safe.
This kind of code lets you do stuff like:
The text was updated successfully, but these errors were encountered: