Skip to content

proposal: cmd/vet: reject unary min and max calls #66179

Description

@dsnet

Proposal Details

A unary min and max call is an identity function and its presence suggests a bug.

I had code that was doing the following:

blockSize = min(max(r.minBlockSize, blockSize, r.maxBlockSize))

where the intent is to clamp blockSize within a certain range.

However, due to a single misplaced ), this does not work.
It should have been:

blockSize = min(max(r.minBlockSize, blockSize), r.maxBlockSize)

I propose that go vet flag any unary calls to min or max, which would have caught my bug where I had 3 arguments passed to max, but only 1 argument passed to min.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions