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

proposal: fmt: print *reflect.Value as reflect.Value #12959

Closed
nodirt opened this issue Oct 16, 2015 · 1 comment
Closed

proposal: fmt: print *reflect.Value as reflect.Value #12959

nodirt opened this issue Oct 16, 2015 · 1 comment

Comments

@nodirt
Copy link
Contributor

@nodirt nodirt commented Oct 16, 2015

Background

fmt treats reflect.Value especially:

If the operand is a reflect.Value, the concrete value it
holds is printed as if it was the operand.

The commit that introduced this behavior has message:

When a reflect.Value is passed to Printf (etc.), fmt called the
String method, which does not disclose its contents. To get the
contents, one could call Value.Interface(), but that is illegal
if the Value is not exported or otherwise forbidden.

The motivation was to disclose the contents of a reflect.Value.

However, fmt doesn't disclose the contents of a *reflect.Value, which is inconsistent.

v := reflect.ValueOf(true)
fmt.Sprintf(v) == "true"
fmt.Sprintf(&v) == "<bool Value>"

https://play.golang.org/p/EcJkj0bx8b

Proposal

Modify the spec to

If the operand is a reflect.Value or *reflect.Value, the concrete value it
holds is printed as if it was the operand.

and make corresponding changes to the implementation.

Examples

v := reflect.ValueOf(true)
fmt.Print(&v)
// Output: true
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 16, 2015
@nodirt
Copy link
Contributor Author

@nodirt nodirt commented Oct 20, 2015

It is not important.

@nodirt nodirt closed this Oct 20, 2015
@golang golang locked and limited conversation to collaborators Oct 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.