-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add a hint if a package uses Future but does not import it from dart:async, and pubspec SDK constraint is too old #35162
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
@bwilkerson or @scheglov, can one of you look into this? |
Did you intend to include @pq?
If there's no pubspec, then I think analyzer should assume that the package is intended to work with the version of the SDK from which the analyzer is being run (that is, the latest, which means don't produce any hints).
We don't use pubspec files in Bazel, so I think it should default to the behavior described above.
I think we should. I think analyzer should create a hint if Future is imported from 'core', which means that it isn't imported from any other library. I don't think it's that much harder to check.
It needs to only make changes if it understands the format and can do so correctly. We might be able to look at a few well known packages on Github and see what formats are currently being used. It's possible that there's not that many being used for the SDK constraint. |
Confirmed that the earliest version of the SDK in which |
SGTM |
@bwilkerson : are you thinking of enhancing the existing |
No, I wasn't. I don't think we need to visit the whole file to extract the sdk constraints. We should probably parse it as YAML to account for all the valid syntaxes, but we just need to extract the one value. Ideally we'd piggy-back on top of the work that @srawlins is doing to better support a notion of packages. The constraints are specified by the package, and this would allow us to do the right thing for packages that don't use a pubspec file. Unfortunately, I don't know that we can wait that long before implementing this feature. |
Yeah, since we want to cherry-pick the fix onto 2.1.1, it can't depend on @srawlins' work. I think it's ok if the bug gets fixed in a somewhat kludgy way for now, and then as part of #34978 we can clean it up to take advantage of Sam's work. |
Hint creation implemented by: |
I did some experiments and found that cherry-picking these CLs to the dev branch leads to test failures, due to the fact that they relied on code that was in the analyzer branch but not yet landed on master. So @bwilkerson is going to try cherry-picking them to master and fixing up the resulting failures. |
In Dart SDK version 2.1.0-dev.5.0, dart:core was modified so that it exports the classes Future and Stream. (Previously these classes were only available via an import of dart:async). Some of the useages of Future and Stream in Flutter fail to import dart:async, therefore in order to work correctly Flutter requires Dart SDK version 2.1.0-dev.5.0 or later. The Dart analyzer team is in the process of implementing a hint to help users remember to update their pubspecs when using Future or Stream and not importing dart:async (dart-lang/sdk#35162). In order to avoid Flutter failing this hint when it lands, we need to update the pubspecs now.
There is now a fix for the first two checkboxes on master that can be cherry-picked. I've submitted a cherry-pick request here: #35232 |
Remaining work is P2 |
The quick fixes are implemented by https://dart-review.googlesource.com/c/sdk/+/84691. |
So, analysis result signatures depend on it and recomputed when it is changed. Also, change analysis server to update analysis options not only when analysis_options.yaml is changed, but also when pubspec.yaml is changed. [email protected], [email protected] Bug: #35162 Change-Id: If4b937c26212d3da74ac7125eb2c6f70dbcb1793 Reviewed-on: https://dart-review.googlesource.com/c/85405 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]>
Isn't this kind of thing happening all the time? I mean, we keep adding features to Dart, right? Do we have a lint for each one to ask that the SDK constraint be moved up? |
This situation was somewhat unique in the wider opportunity for misuse. It's true that there are always new features going in and using them requires an SDK constraint. This feature looks a little different from most:
That said, I think even other changes are things we'd like to help catch, this was the most critical one. |
This would address a small, targeted subset of #34978 that we believe will be particularly troublesome for customers. Tasks to do:
dart:core
began exportingFuture
was 2.1.0-dev.5.0.Future
that would not have worked prior to the above SDK version, and the user's pubspec SDK constraint includes a lower-bound version of the SDK prior to 2.1.0-dev.5.0Ideally, all these changes should be made in such a way that they can be cherry-picked to the dev branch of the SDK repo, so that they can be released as part of 2.1.1. However, if it's not feasible to do this for the "if time allows" items that's ok.
Yet to be determined (suggestions welcome):
a.dart
importsb.dart
and usesFuture
;b.dart
exportsdart:async
. Theoretically this is ok but it may not be worth trying to make the analyzer handle this case correctly)The text was updated successfully, but these errors were encountered: