Skip to content

Analyzer should recognize features not accepted by a package's minimum required SDK version. #34978

@lrhn

Description

@lrhn

Example: In Dart 2.1, the dart:core library re-exports Future and Stream from dart:async.

If you write a package and use Future or Stream without an import, the 2.1.0 analyzer will say that is perfectly OK. However, if your pubspec SDK version requirment allows a 2.0.0 SDK, then the code might not work there.

Similarly, Dart 2.1 introduced the ability to use integer literals in a double context, as a shorthand for the double litteral. Again, code using this with an SDK requirement below 2.1.0 is not correct.

Each Dart SDK released can introduce new non-breaking language features or library extensions. The analyzer should keep track of those changes and compare them to the minimum required SDK allowed by a package.

For language features, the versioning information will likely need to be hard-coded into the analyzer.
For library changes, we could introduce an annotation like @Since("2.1") on new parts of the API, which would apply to entire libraries, exports, single declarations, or even individual parameters.
(We can't mark API removals that way, but removals are breaking changes, so we will likely only do them on major version increments anyway. We can add version numbers to deprecations before we remove the feature, so something can be @Deprecated(since: "2.2"), but I'm not sure that's actually helpful. Or we can document removed fatures @Deprecated.andRemoved(namedArgument: #foo).)
It might be easier to just maintain a structured API changelog on the side.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions