Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jba opened this issue Apr 16, 2025 · 1 comment
Open

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

jba opened this issue Apr 16, 2025 · 1 comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@jba
Copy link
Contributor

jba commented Apr 16, 2025

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.

@jba jba added the Proposal label Apr 16, 2025
@gopherbot gopherbot added this to the Proposal milestone Apr 16, 2025
@gabyhelp
Copy link

Related Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Projects
None yet
Development

No branches or pull requests

3 participants