Skip to content

cmd/vet: consider reporting invalid/ignored Go versions in build tags #64127

Closed

Description

@griesemer

Files may specify their own Go language version via a build tag. For instance:

//go:build go1.22

indicates that this file requires Go language version 1.22.

If the language version in the build tag contains dot-release information, say it's "go1.22.1", it is invalid.
The compiler simply ignores the version (it doesn't use, say "go1.22").

It seems (to me) that this shouldn't be silently ignored as it might be very confusing for users. go vet might be the right tool to report an error. Alternatively, the compiler could report an error, but generally, the compiler doesn't complain about errors in (pragma and build) comments.

Activity

  1. added this to the Proposal milestone on Nov 14, 2023
  2. timothy-king commented on Nov 14, 2023

    @timothy-king
    Contributor

    go/analysis/passes/buildtag would be a good home for this check.

  3. Goclipse27 commented on Nov 15, 2023

    @Goclipse27
  4. moved this to Incoming in Proposalson Nov 15, 2023
  5. Goclipse27 commented on Nov 16, 2023

    @Goclipse27
    Contributor

    @griesemer @ianlancetaylor - Do you consider handling tags including expression like go:build go1.21 && go1.22.3 or a single tag ?

  6. Goclipse27 commented on Nov 16, 2023

    @Goclipse27
  7. griesemer commented on Nov 16, 2023

    @griesemer
    ContributorAuthor

    It should report any Go version string that is silently dropped and ignored.
    Also, before anybody starts working on this: note this is a proposal and needs to be discussed by the proposal review committee first. Thanks.

  8. added
    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)
    on May 29, 2024
  9. rsc commented on May 30, 2024

    @rsc
    Contributor

    We already have a //go:build line checker. It should definitely report these.

  10. moved this from Incoming to Active in Proposalson May 30, 2024
  11. rsc commented on May 30, 2024

    @rsc
    Contributor

    This proposal has been added to the active column of the proposals project
    and will now be reviewed at the weekly proposal review meetings.
    — rsc for the proposal review group

  12. rsc commented on Jun 5, 2024

    @rsc
    Contributor

    No change in consensus, so accepted. 🎉
    This issue now tracks the work of implementing the proposal.
    — rsc for the proposal review group

    The proposal is for the ‘buildtag’ checker to report build tags of the form go1.X.Y since only go1.X is recognized in build tags.

  13. moved this from Active to Accepted in Proposalson Jun 5, 2024
  14. 5 remaining items

  15. modified the milestones: Backlog, Go1.24 on Jul 29, 2024
  16. dmitshur commented on Nov 26, 2024

    @dmitshur
    Member

    A new check added to vet seems like something that needs to be mentioned in Go 1.24 release notes, and it's not mentioned there yet. Reopening as a release blocker for tracking that.

  17. gopherbot commented on Nov 27, 2024

    @gopherbot
    Contributor

    Change https://go.dev/cl/632355 mentions this issue: doc/next: document buildtag changes

  18. added a commit that references this issue on Nov 28, 2024
    797141e
  19. added a commit that references this issue on Feb 13, 2025
    55d718e
  20. locked and limited conversation to collaborators on Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions