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

text/template: documentation for IsTrue disagrees with its implementation for struct types #28394

bcmills opened this issue Oct 25, 2018 · 5 comments
Documentation NeedsFix


Copy link

@bcmills bcmills commented Oct 25, 2018

As noted in #28391, the documentation for template.IsTrue says:

IsTrue reports whether the value is 'true', in the sense of not the zero of its type, and whether the value has a meaningful truth value.

The zero time.Time is the zero of its type, so according to the documentation it should be considered to be true, but the implementation clearly intends otherwise:

case reflect.Struct:
truth = true // Struct values are always true.

Either the documentation should be clarified, or the behavior of IsTrue should be fixed to match what is documented. Probably the former.

@bcmills bcmills added Documentation NeedsDecision labels Oct 25, 2018
@bcmills bcmills added this to the Go1.12 milestone Oct 25, 2018
Copy link
Member Author

@bcmills bcmills commented Oct 25, 2018

CC: @robpike @mvdan

Copy link

@mvdan mvdan commented Oct 25, 2018

Struct values have always been true in the implementation since 2011: 1adda46

So I'd agree that this is a minor documentation issue.

Copy link

@gopherbot gopherbot commented Oct 25, 2018

Change mentions this issue: text/template: clarify truthiness of structs

Copy link

@rsc rsc commented Nov 14, 2018

If the decision was document or fix, document it. As @mvdan says, it's been that way for a long time. It's not worth a semantic change.

@rsc rsc added the NeedsFix label Nov 14, 2018
@gopherbot gopherbot removed the NeedsDecision label Nov 14, 2018
@robpike robpike self-assigned this Nov 14, 2018
Copy link

@mvdan mvdan commented Nov 14, 2018

@robpike given that you've self-assigned this - do you want me to abandon my CL?

@andybons andybons removed this from the Go1.12 milestone Feb 12, 2019
@andybons andybons added this to the Go1.13 milestone Feb 12, 2019
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@andybons andybons added this to the Go1.14 milestone Jul 8, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Documentation NeedsFix
None yet

No branches or pull requests

6 participants