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

Comments

Projects
None yet
5 participants
@bcmills
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 this to the Go1.12 milestone Oct 25, 2018

@bcmills

This comment has been minimized.

Member

bcmills commented Oct 25, 2018

@mvdan

This comment has been minimized.

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

This comment has been minimized.

gopherbot commented Oct 25, 2018

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

@rsc

This comment has been minimized.

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 label Nov 14, 2018

@robpike robpike self-assigned this Nov 14, 2018

@mvdan

This comment has been minimized.

Member

mvdan commented Nov 14, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment