Skip to content

fmt.Formatter is not called for %T #73528

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

Closed
anacrolix opened this issue Apr 29, 2025 · 4 comments
Closed

fmt.Formatter is not called for %T #73528

anacrolix opened this issue Apr 29, 2025 · 4 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@anacrolix
Copy link
Contributor

Go version

main

Output of go env in your module/workspace:

irrelevant

What did you do?

Pass %T to a format function with an arg that implements fmt.Formatter

fmt.Formatter.Format is not invoked for %T verb. It's also not documented. I believe %p is the same.

What did you see happen?

The type of the arg is printed, rather than performing the action of fmt.Formatter.Format for the type with the T verb.

What did you expect to see?

The result of executing fmt.Formatter.Format for the arg's type.

@robpike
Copy link
Contributor

robpike commented Apr 29, 2025

Although one could argue it should pass T to the Formatter, I intended it for debugging and so it deliberately ignores all the non-standard routes.

So perhaps unfortunate in your case but it's working as intended, according to its author.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Apr 29, 2025
@rittneje
Copy link
Contributor

This is documented.

Except when printed using the verbs %T and %p, special formatting considerations apply for operands that implement certain interfaces.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2025
@anacrolix
Copy link
Contributor Author

Thanks, don't know how I missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

5 participants