Skip to content

proposal: cmd/vet: unusedresult should accept a list of functions whose results _may be unused_ (inverse sense to -funcs flag) #65984

Description

@janpfeifer

Proposal Details

Similar in spirit to proposal #20803 (for the go compiler), and related to #63689, #14972, and #20148.

I recently lost time on a subtle bug where I forgot to use the result of a function. I tried to simplify the issue to a minimal example:

func f(x float64) float64 {
	math.Sqrt(16.0)  // No warning!?
	return x + 1.0
}

Currently, go vet will only catch this if I list -unusedfuncs=math.Sqrt. But I would only add math.Sqrt if I already knew about the bug, which defies the go vet purpose. I would like to pass all my projects functions/methods and its dependencies (including standard library) to -unusedfuncs.

Instead, can we have an alternative flag -unusedignorefuncs (or something else) where one can pass a "blacklist", and every other function whose results are unused are reported back ? (maybe with some defaults, like fmt.Printf) ?

I understand a similar point is being made for the compiler (and extra syntax?) in proposal #20803.

Having a "blacklist" option to go vet could also be an intermediary solution for that proposal -- for those using go vet systematically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions