Skip to content

Dart analyzer misses compile time type error #43045

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

Closed
ristiisa opened this issue Aug 14, 2020 · 1 comment
Closed

Dart analyzer misses compile time type error #43045

ristiisa opened this issue Aug 14, 2020 · 1 comment
Labels
closed-duplicate Closed in favor of an existing report

Comments

@ristiisa
Copy link

The following code should produce compile time error but still fails at run time:

void main() {
  int i = true ? "1.0" : 0;
  print(i);
}

this is not a duplicate of #25368 since no strong mode is used.

Dart SDK version: 2.9.0-21.0.dev.flutter-20bf2fcf56 (be) (Tue Jul 14 09:46:23 2020 +0000) on "macos_x64"

@eernstg eernstg added the closed-duplicate Closed in favor of an existing report label Aug 14, 2020
@eernstg
Copy link
Member

eernstg commented Aug 14, 2020

It is actually a duplicate of #25368. I'm not quite sure what you mean by strong mode. Before Dart 2 it was a way to enable Dart2-ish type checking, which is more strict than Dart 1 type checking; recently, it has been used to denote the execution of programs with null safety in the sound (and strict) mode where no legacy code can occur in the whole program.

In any case, the issue is that there is an upcast for "1.0" and for 0 because the type of the conditional expression true ? "1.0" : 0 is Object, and then there's an implicit downcast to int. With null safety (and with '--no-implicit-casts`), you will get the compile-time error.

@eernstg eernstg closed this as completed Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

2 participants