Skip to content

"pub downgrade" may resolve with package versions incompatible with Dart 3Β #52355

@rrousselGit

Description

@rrousselGit

Hello!

There appears to be an unfortunate side-effect to treating constraints such as sdk: >=2.x.z <3.0.0 as sdk: >=2.x.z <4.0.0.
This effectively marks versions non-compatible with the breaking changes in Dart 3.0 to be compatible with it anyway.

As an example, consider a package A that:

  • in version 1.0.0 is using NullThrownError, which was removed in Dart 3
  • has for SDK constraint sdk: >=2.x.z <3.0.0, which matches with what the package supports
  • has a more recent version 1.1.0 available that is Dart 3 compatible (as in, its sdk constraint explicitly allows Dart 3)

Then, a second package B depends on package A, but with looser version constraints.

  • package B is compatible with both Dart 2 and Dart 3
  • package B is also compatible with all versions of package A

In that situation, B has effectively for pubspec:

name: b
environment:
  sdk: ">=2.12.0 <4.0.0"
dependencies:
  a: ^1.0.0

With those constraints, there is now an issue when running pub downgrade on an app depending on B when using Dart 3.

Instead of resolving the version of A with v1.1.0 which is Dart 3 compatible, the command will resolve with v1.0.0 which is not Dart 3 compatible.
As such, the application will fail to start.

This is confusing because, at all points, the package authors and application authors used the correct version constraints.

  • The author of A correctly said Dart 3 wasn't supported in their version 1.0.0 and correctly published a newer Dart 3 compatible version
  • The author of B correctly supports Dart 2 and 3 at the same time
  • The app author which depends on B doesn't use A, so they shouldn't have to care about the minimum A version

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-cliUse area-dart-cli for issues related to the 'dart' command like tool.dart-cli-pubIssues related to the 'dart pub' tool

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions