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

Open
bcmills opened this issue Oct 25, 2018 · 5 comments
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bcmills
Copy link
Member

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 Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 25, 2018
@bcmills bcmills added this to the Go1.12 milestone Oct 25, 2018
@bcmills
Copy link
Member Author

bcmills commented Oct 25, 2018

CC: @robpike @mvdan

@mvdan
Copy link
Member

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.

@gopherbot
Copy link

Change https://golang.org/cl/144657 mentions this issue: text/template: clarify truthiness of structs

@rsc
Copy link
Contributor

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 The path to resolution is known, but the work has not been done. label Nov 14, 2018
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Nov 14, 2018
@robpike robpike self-assigned this Nov 14, 2018
@mvdan
Copy link
Member

mvdan commented Nov 14, 2018

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

@andybons andybons modified the milestones: Go1.12, Go1.13 Feb 12, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants