Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
reflect: StructOf doesn't generate wrapper methods for embedded fields #15924
I expected that x would have generated wrapper methods for Mutex.Lock, etc.
Interestingly, adding this declaration inside func main (not at package level):
causes the program to succeed. Presumably it causes the compiler to generate the correct type information, which
FYI, as of CL 100846, methods are now sorted with exported names before non-exported names, and there's an extra field to track the number of exported methods.
The current code works because it only allows exported methods from one type, so they're already in the same sort order, and we don't need to worry about counting how many exported methods there are. If either of those constraints change, we'll need to change the code (e.g., to sort methods and/or count the exported methods). I've left TODOs to mark where I expect this needs to be done.
Also, one other comment: currently, StructOf only allows promoting methods from the first field, but it could be generalized slightly to allowing promoting methods of any field with offset==0. This would allow methods from multiple zero-width types to be promoted.
Alas, it seems not.
The following example crashes with SIGSEGV on both my local Go 1.11.4 installation and on playground https://play.golang.org/p/jny1YKZsHlp
on my local Go 1.11.4, the output is:
on playground https://play.golang.org/p/jny1YKZsHlp the output is instead:
I would expect that either
83092a4#diff-cdbb65f700222dd514ff85e972c88be2R2470 broke my program after I've updated the Go version.
I didn't use any of the the struct methods. The struct was built only to create dynamic data structures matching a specific format when encoded with various encoders such encoding/json.
@mihaiav I'm sorry that happened but given the choice between "incorrectly claim we did what the program requested" and "give an error" I think it's better to give an error.
You should be able to fix your program by making a regular field rather than an embedded field.