Skip to content

VersionConstraint.intersection can throw TypeError in some cases #2608

Closed

Description

@ardera

the VersionConstraint.intersection factory casts all the intersections a.intersect(b) to a VersionRange:

constraint = constraint.intersect(other) as VersionRange;

but the intersect method will sometimes return an empty range (_EmptyVersion), which is not a subtype of VersionRange, so you get a TypeError

Activity

  1. added
    type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)
    on Sep 29, 2026
  2. agam1092005 commented on Sep 30, 2026

    @agam1092005

    I investigated this and confirmed the TypeError occurs because VersionConstraint.intersection() casts every result of intersect() to VersionRange, while intersections can return _EmptyVersion, Version, or VersionUnion.

    I’m thinking of changing the local variable to VersionConstraint, returning early when the result is empty, and adding tests for disjoint ranges and single-version intersections.
    Would this approach be acceptable?

    @ardera @lrhn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package:pub_semvertype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions