-
Notifications
You must be signed in to change notification settings - Fork 1.7k
No error in CFE for promoted type variable of wrong type #42089
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
Interesting. @johnniwinther, it looks like the CFE might create types of the form [Edit: Some kind of promotion seems to happen, otherwise it shouldn't make a difference to remove |
@eernstg - should we file this as a CFE issue or a language one? |
I suspect that it would be too big for a language issue (the implications could be substantial if we start generalizing promoted types to have other forms than |
I see no need for a language change. |
The relevant portion of the spec is in
There is no promotion specified to happen in this case, and in fact, the CFE seems to be going completely off the rails here. The following program runs in the CFE and calls test<X>(X? x) {
if (x is String?) {
Object o = x; // Error in analyzer. A value of type 'X?' can't be assigned to a variable of type 'Object'
x.length;
}
}
main() {
test<String>(null);
} |
Would we want to be able to promote That could account for foo<X extends Object>(X? x) {
if (x is String?) ... /* x is (X & String)? */
} (There are probably lots of issues with that, but it looks so plausible that users might expect it to work). |
We could push on it. It hasn't come up in migrations yet, and the ship is sailing, so I think this is probably not making it into v1. |
The code below produces compile-time error in analyzer and no issues in CFE
If to remove
if (x is String?) {
from functiontest
then CFE starts produce an error as wellDart VM version: 2.9.0-11.0.dev (dev) (Tue May 26 12:14:57 2020 +0200) on "windows_x64"
The text was updated successfully, but these errors were encountered: