Skip to content
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

Incorrect type cast for FutureOr #34276

Closed
iarkh opened this issue Aug 27, 2018 · 3 comments
Closed

Incorrect type cast for FutureOr #34276

iarkh opened this issue Aug 27, 2018 · 3 comments
Labels
closed-as-intended Closed as the reported issue is expected behavior

Comments

@iarkh
Copy link
Contributor

iarkh commented Aug 27, 2018

Dart SDK Version: 2.1.0-dev.2.0
OS: Windows 10 (64 bit)

I am not 100% sure that this is not a duplicate of #34264, however on the firs glance these cases looks different.

The following code sample assign FutureOr variable (without type parameter specified) to int and then prints it:

import "dart:async";

main() {
 FutureOr fff;
 int i = fff;
 print(i);
}

It passes both with analyzer and dart,no compiler errors and dart prints null value here.

I'm just wandering - should not it fail here in the strong mode?

Please note that if I change FutureOr to Future this test starts to fail both with analyzer and dart,, from my point of view this is expected behavior both for Future and FutureOr.

@matanlurey matanlurey added the closed-as-intended Closed as the reported issue is expected behavior label Aug 27, 2018
@matanlurey
Copy link
Contributor

This is (unfortunately) WAI: #31410.

FutureOr really means FutureOr<dynamic> (#33119), and FutureOr<dynamic> is a poor-man's "union type" of Future<dynamic> and dynamic. Of course, dynamic is statically assignable to int (with a runtime check), and it succeeds because everything is nullable right now (null is valid for anything).

/cc @lrhn if you have anything else to add, but I'll close for now.

@iarkh
Copy link
Contributor Author

iarkh commented Aug 28, 2018

In this case, should not case with Future (instead of FutureOr) in the example above statically pass in the same way? Now it fails both with analyzer and dart.

@matanlurey
Copy link
Contributor

No, Future is not assignable to int. FutureOr is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants