-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Dart type checking became more strict #5605
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
So this is a recent VM change, which was picked up in a flutter/engine roll. Is this expected @a-siva? |
CC @pq since the analyzer doesn't warn about this? |
Does your .analysis_options file turn on all the type checking? |
cc @bwilkerson @jmesserly who may have better insight into the analysis side of things. |
Was this error produced by running the AOT compiler? |
This is just a checked mode failure. This hasn't ever worked in Dart. $ cat test.dart double get packedPercent => 0;
main() { print(packedPercent); } $ dartanalyzer test.dart
$ dartanalyzer --strong test.dart
$ dart -c test.dart
|
This currently runs on dartpad with no issues and no analyzer warnings. It will fail on the VM flutter uses. CONSOLE
https://dartpad.dartlang.org/53bd8d3a960c49b0f8f22b80362aec13 |
dart2js has limitations with respect to how closely it implements dart's rules about numbers, due to JS only having one number type. |
Not sure if analyzer knows what to do here, when ternary operator returns either int or double, and the function is marked to return a double. I'd expect an analyzer warning, regardless of later being compiled with dart2js. cc @bwilkerson ? |
They do not appear to have "checked mode" turned on in dartpad. So type annotations are more or less ignored.
@sethladd Analyzer knows what to do. It concludes "num", which is then implicitly downcast to "double". All of our modes allow it, if you want to disable downcasts use the recently introduced (in 1.19) --no-implicit-casts flag of strong mode. See: http://news.dartlang.org/2016/08/dart-119-improved-developer-experiences.html |
Oops I should've linked to the changelog: |
@jmesserly kk, thanks! (all these modes and options and lints and features are making my head swim) |
~$ dart --version
~$ dartanalyzer --version
~$ cat test.dart
~$ dartanalyzer test.dart
~$ dartanalyzer --strong test.dart
~$ dart test.dart
~$ dart -c test.dart
|
yeah no kidding! If it helps to know, things will get better :). Strong mode will be "the only mode". Things like --no-implicit-casts are ways for us to gracefully introduce stricter checking we think is a good idea, and determine if it can be rolled into strong mode. |
Hi! How do we take action on this issue? Is this something for Flutter to do? cc @floitschG |
I guess this is more of a dart issue, but it was noticed in our application from a flutter engine roll. The dart bug would be something like
Should produce an error in dart analyzer but does not. Calling this function fails when running with |
Unfortunately in Dart1 this is not an error, but an implicit downcast :( |
Yes, this is on long list of small but annoying problems to fix. |
@sethladd: the code is bad since it tries to return an integer where a double was required. If it hasn't been updated yet, it should be. |
Fair enough. I've asked @drewwarren if we can change the code to return |
The customer's code has been fixed. They would love if the analyzer can detect if one of the cases of the ternary returns an incorrect type. In the meantime, we can close this issue in favor of dart-lang/sdk#25368 |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
I have a function
This function used to work fine, even when deadline.totalItems was 0. Now it fails when a type error when deadline.totalItems is 0.
I'm guessing this is because I am returning an int 0 instead of a double 0.0.
I do not get any output from dart analysis related to this, even when using https://github.com/raw/flutter/flutter/master/.analysis_options
The text was updated successfully, but these errors were encountered: