-
Notifications
You must be signed in to change notification settings - Fork 18k
builtin: len godoc can lead the reader to believe that len(nil) is valid #30349
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
Comments
https://play.golang.org/p/3-iF20WnP2I demonstrates the same behavior in Go without templates. It might indeed need a tweak to the spec. I'm not sure. Let's ask @griesemer |
I think you should adjust the implementation of |
But then again, I assume that a |
Reading the builtin godoc linked above:
The way I'm reading it is that "if v is one of the types above and its value is nil, len(v) is zero". Perhaps that should be made clearer. In any case, I don't think it makes sense to allow |
Actually, I misread the punctuation. It's actually saying:
So this seems like just a formatting issue in the rendered godoc. |
#7873 has a proposal for lists. The preformatted style intended for source code is very awkward for lists like this. |
Thanks for the link, that's quite interesting. Though I think we can improve the situation here without waiting for a resolution to that issue. For example, we could make the channel line longer, or we could indent its continuation:
|
I do not think there is a compelling need to make len(nil) be zero. Remember an untyped nil is literally the constant nil; asking its length is pointless. Other than possibly reformatting the text as suggested, I see nothing here worth doing. |
Makes sense. I think the confusion is that Hugo users may call {{ range first 1 (default slice .Site.Params.images) }}
<image>
<url>{{ . }}</url>
</image>
{{ end }} |
pointer assignments return nil by design golang/go#30349 closes #136 updates #135
@robpike note that the apparent consensus we reached is not about allowing |
Change https://golang.org/cl/167403 mentions this issue: |
This fails with:
This behaviour does not match the documented behaviour at https://golang.org/pkg/builtin/#len
gohugoio/hugo#5708
The text was updated successfully, but these errors were encountered: