Skip to content

x/mod: semver.Max does more than compute the max #32700

@bcmills

Description

@bcmills

Currently, semver.Max canonicalizes its arguments according to semver.Canonical:
https://play.golang.org/p/04IP9gNhFWH

To me, the name Max does not evoke “canonicalize”, and the action of canonicalizing is potentially fairly destructive: for example, if I have a version with a +incompatible build suffix, that version is canonical according to module.CanonicalVersion, but will not be preserved by a call to semver.Max.

@rsc points out that the canonicalization avoids ambiguity: v0.1.0+a and v0.1.0+b have the same precedence, so if we call semver.Max("v0.1.0+a", "v0.1.0+b") we would otherwise have to pick one arbitrarily, and semver.org says “Build metadata SHOULD be ignored when determining version precedence.”

Instead, I propose that Max should always return one of its arguments. Build metadata must comprise only the usual dot-separated ASCII identifiers, so if we have two versions with equal precedence it seems to me that we could break the tie using the usual rule for comparing pre-release suffixes.

CC @jayconrod @hyangah

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.modules

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions