Skip to content

proposal: go/types: add TypeAndValue.IsConstant #73402

Open
@jba

Description

@jba

Proposal Details

I propose adding the following method to go/types:

IsConstant reports whether tv represents a constant.
func (tv TypeAndValue) IsConstant() bool { return tv.Value != nil }

Calling tv.IsConstant() is clearer than writing tv.Value != nil, and avoids confusion with tv.IsValue(), which tests something different.

Motivation: much code in x/tools uses tv.Value != nil, often with no explanation, making challenging code even harder to understand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions