-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer: no implicit cast errors for most downcasts to iterable #36267
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
@lrhn and I just discussed the extent to which we can insist that a desugaring specification can be used to determine compile-time errors. I would like to say that the rewritten code shows whether there are any errors, but the original code should (of course) be the sole reference that error messages can refer to. But for-in desugars to a while statement, and in this case we would get the following outcome: Object o;
dynamic d;
for (var x in o) {} // An error exists, because `o.iterator` is an error.
for (int x in d) {} // OK; dynamic lookups `d.iterator`, `n0.current` and cast to `int`.
for (int x in o) {} // Error exists, `o.iterator` again.
for (var x in d) {} // OK, has `d.iterator`, `n0.current`, `x` has type `dynamic`. The error messages would not be able to refer to PS: The title seems to imply that |
Yes, that's the issue here, is that turning that flag on doesn't do anything here. I'm not so sure about
I suppose I can see this being OK because it's simply pure dynamic code. But I don't like it! :) I would expect the desugared code to do:
after all, this code aborts because NotIterable is not an Iterable.
|
We discussed that approach in the language team, but for-in is actually specified to desugar to a snippet of code where the type of the iterable is not required to be But I can see that both Created a pull request in order to make the spec say that it must be an The discussion about |
The implementation is extremely simple: wire strict-casts right alongside implicit-casts in AnalysisOptionsImpl, AnalysisSession, and TypeSystem. The flag is separate from implicit-casts because it is _slightly_ stricter. The implicit-casts flag has some gaps in coverage (like for-each iterables, and yield-each expressions). Filling these gaps in implicit-casts would be expensive (requiring cleanup), and the short-term goal is to deprecate the flag, so it is not important to tidy it up. A few extra bits are then added which are specific to strict-casts, which improve the coverage. Most of this change is the tests: tests are added for (theoretically) each error code which could be reported as a result of strict-casts. The test model using WithStrictCasts follows the model of WithStrictCasts, which couples two tests into one assertion, ensuring the state of each example code before and after strict-casts. Bug: #36267 Change-Id: I52b2fc831fac3a5467ec7164df8fc1a1109e42ef #33749 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219847 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
I'm closing this as WAI. The spec is now pretty clear, and analyzer's new |
The same behavior occurs for spread collections.
I would expect that all of these would be flagged based on the fact that all four of these assignments are flagged:
The text was updated successfully, but these errors were encountered: