-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/godoc: treat function returning slice as constructor #18063
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
Before considering whether the There may be strange edge-cases, but grouping slices and arrays of a given type seems reasonable to me. |
Right - even after a few years I still get confused between
Out of curiosity, why is that? I would assume the logic behind the two - at least the logic concerning constructor funcs - would be the same. |
As of late, the behavior of |
we need to consider how far do we want to get into reordering.
e.g. what about []struct{T}, []struct{T;U}, [][]T, []*T, [][]*T, []*[]T,
map[string]T, ... and the list goes on and on.
|
This proposal is limited to just slices whose element types are already grouped as constructors. So if funcs that return |
Not sure why I didn't make this a proposal from the start; made it one. |
/cc @griesemer |
These would be the "new" constructors in the standard library:
At least four of these look like actual constructors. LookupMX and LookupNS are arguably not. (Of course, user.LookupId is considered a constructor for *user.User, so capturing those would be consistent at least.) (There are a bunch of methods returning slices of things in the same package too, but methods are never "constructors".) It does seem like it's probably reasonable. |
accepting for @golang/proposal-review. If anyone is interested to work on this, a CL would be welcome. |
Happy to work on a patch for 1.10. |
@rsc by the way, why was the title changed to remove |
Hey @mvdan are you still working on this? I was inspired by the recent contribution workshop blog post (https://blog.golang.org/contributor-workshop) and went hunting for bugs. I have a change working locally, would you mind if I submitted a CL? |
@tomwans nope, I was going to get to this after the holidays. Go ahead. |
Change https://golang.org/cl/54971 mentions this issue: |
This is sort of a follow-up to #14004. Sometimes, there are constructors that return a slice of a type. For example:
https://golang.org/pkg/net/mail/#pkg-index
go/doc
does not considerParseAddressList
anAddress
type func as it returns a slice, not the type directly. Since this rule is reserved for the first returned type, I suggest this is relaxed to also allow slices (and perhaps arrays too? but couldn't find an example of that).CC @aclements @robpike
The text was updated successfully, but these errors were encountered: