Skip to content

cmd/vet: reject flag.Parse during func init #33190

@rsc

Description

@rsc

In #31859, @cespare suggested rejecting flag.Parse during func init, which is always incorrect (other packages not yet initialized may want to define flags).

We could add a special runtime hook of some kind to allow flag to see whether main.main has started, but that would be unfortunate.
There also may be lots of code in the wild that does parse flags during init and kind of works out OK, and if it's working well enough we don't want to break it unnecessarily.

A vet check, on by default during go test, seems like the perfect compromise to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsFixThe path to resolution is known, but the work has not been done.early-in-cycleA change that should be done early in the 3 month dev cycle.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions