-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer fails to respect certain "is" checks #11080
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
Comments
Related to (duplicate of?) https://code.google.com/p/dart/issues/detail?id=6397 |
Added this to the M6 milestone. |
Unfortunately, it has been decided that dartanalyzer and the editor cannot use type inference to eliminate errors and warnings. The only way to get rid of this error would be to write print((list as TypedData).buffer); even though the cast seems redundant. Set owner to @bwilkerson. |
I thought this had been changed in the spec, but it still seems not to work. Was I misinformed? |
It was changed in the specification, but only for a very limited set of cases. The specification reads: Let v be a local variable or a formal parameter. An is-expression of the form v is T shows So in this case, the parameter 'list' would be shown to have type 'TypedData' iff 'TypedData' is more specific than 'List'. Unfortunately, there is no relationship between 'TypedData' and 'List', so we cannot use that information for the purposes of suppressing warnings. If 'TypedData' implemented 'List', then this would work the way you expect. |
I don't understand this limitation. If you enter a code block that's gated by an |
Consider the following code:
In the absence of intersection types you can choose one of two "wrong" semantics. Within the body of the The original authors chose one of the two options, but both are bad. I'm not sure which would result if fewer spurious error messages in practice. Feel free to re-open this case if you want the language team to consider changing this behavior. |
I think the analyzer should assume that in that block, |
(i don't have the access to reopen bugs in the dart sdk repo :-) ) |
We tried adding union types behind the scenes awhile back and it turned out to be so confusing to users that we ended up backing all that out. I'm concerned that intersection types would be the same. In any case, this behavior is currently part of the specification, so I'm turning this into a language issue. |
Looks like a variant of an "improve type promotion" request (#25565) |
Consider the following code:
import "dart:typed_data";
void doIt(List list) {
if (list is TypedData) print(list.buffer);
}
Running the analyzer on this produces the following error:
[warning] There is no such getter 'buffer' in 'List'
despite the fact that "list" must be an instance of TypedData in the "if" block, and TypedData defines a "buffer" getter.
The text was updated successfully, but these errors were encountered: