Skip to content
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

fmt: refers to the empty interface by the longer, older "interface {}" name instead of the shorter, newer "any" #65912

Closed
dmitshur opened this issue Feb 23, 2024 · 5 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Feb 23, 2024

Go version

go version go1.22.0 darwin/arm64

Output of go env in your module/workspace:

N/A

What did you do?

I used fmt's %#v to print a value whose type involves the empty interface in a module that declares Go version 1.22.0.

fmt.Printf("value of []any{1, 2} is %#v\n", []any{1, 2})

https://go.dev/play/p/pByHBo9Vs03

What did you see happen?

value of []any{1, 2} is []interface {}{1, 2}

What did you expect to see?

Go 1.18 added the predeclared type any as an alias for the empty interface.

It might be an enhancement if fmt were to take advantage of it, and print:

value of []any{1, 2} is []any{1, 2}

CC @robpike, @martisch.

@dmitshur dmitshur added FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 23, 2024
@dmitshur dmitshur added this to the Backlog milestone Feb 23, 2024
@cherrymui
Copy link
Member

any is defined as an alias to interface{}. We print the byte type as the unaliased uint8, so we probably should print any as the unaliased interface{} as well.

@cherrymui
Copy link
Member

Well, for byte, when printing the type (%T) it prints uint8, but when printing value (%#v) it prints byte. For rune we print int32 for both. https://go.dev/play/p/yttrKyuyZrP . That seems inconsistent.

@go101
Copy link

go101 commented Feb 23, 2024

See #44391 and #14830.

@robpike
Copy link
Contributor

robpike commented Feb 23, 2024

I wouldn't change this. It's clear and also has the potential to break a lot of golden files.

@dmitshur
Copy link
Contributor Author

It sounds like this is okay to leave as is then. If in the future this change (possibly bundled with others like it) gets a higher benefit-to-cost ratio, a new issue can be filed (referencing this one). Thanks for considering it.

@dmitshur dmitshur closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants