-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
reflect: can't call methods on StructOf with embedded interface field #38783
Comments
I'm not sure if this is supposed to be supported or not. I did a bit of digging and this whole method table setup for embedded interface types stood out to me as suspect especially since there is no test coverage going over it, but I'm not familiar enough with the Go internals to really figure this out: Lines 2466 to 2471 in 4209a9f
In particular, the This may also be related to #16522 but I hope not! Also maybe related to #15924 because this comment found the same issue: #15924 (comment) |
This is not expected to work at present, but it should panic or fail rather than getting a segmentation fault. |
DO NOT SUBMIT INCOMPLETE PATCH Previously, a call to a StructOf method from an embedded interface field would cause a segfault, so fix the behaviour to either succeed in calling the method or, if available method slots have been exhausted, cause a clean panic. Updates golang#38783
@mitchellh TheCount@b97bc37 contains a fix at least for your particular issue. What's going on:
This patch has some deficiencies:
@ianlancetaylor Can you give me some advice how to proceed from here? Should I create a pull request despite the deficiencies? Or connect to some people first (who?)? TIA! |
@TheCount This seems complicated enough that it's probably worth writing a little design doc for how to implement this. I think the limitations you describe are a bit too extreme, as they will cause programs to work in limited cases but fail surprisingly in general. Perhaps the best person to review a design doc would be @randall77 . Thanks. |
Sure, I can take a look when it is ready. |
DO NOT SUBMIT INCOMPLETE PATCH Previously, a call to a StructOf method from an embedded interface field would cause a segfault, so fix the behaviour to either succeed in calling the method or, if available method slots have been exhausted, cause a clean panic. Updates golang#38783 Update 2023/09/03: Commit rebased onto current master. However, ·dispatchLabel assumes the old ABI0, which is wrong, causing this patch to not work.
Sorry for dropping the ball on this. FWIW, in TheCount/go@155eedb I adapted my initial patch to the current version of Go. However, the simple little dispatch hack in I'll see whether I can find the time to write that design doc. No promises, though. Sorry. |
Use abi.FuncPCABIInternal instead of going through assembly or unsafe.Pointer hacks. For golang#38783
Move amd64-specific definitions from general makefunc.go to amd64-specific makefunc_amd64.go. For golang#38783
DO NOT SUBMIT INCOMPLETE PATCH Previously, a call to a StructOf method from an embedded interface field would cause a segfault, so fix the behaviour to either succeed in calling the method or, if available method slots have been exhausted, cause a clean panic. Updates golang#38783 Update 2023/09/03: Commit rebased onto current master. However, ·dispatchLabel assumes the old ABI0, which is wrong, causing this patch to not work.
Use abi.FuncPCABIInternal instead of going through assembly or unsafe.Pointer hacks. For golang#38783
Move amd64-specific definitions from general makefunc.go to amd64-specific makefunc_amd64.go. For golang#38783
Implement struct type creation for struct types with one embedded interface. No limit on the number of such struct types that can be created. For golang#38783
DO NOT SUBMIT INCOMPLETE PATCH Previously, a call to a StructOf method from an embedded interface field would cause a segfault, so fix the behaviour to either succeed in calling the method or, if available method slots have been exhausted, cause a clean panic. Updates golang#38783 Update 2023/09/03: Commit rebased onto current master. However, ·dispatchLabel assumes the old ABI0, which is wrong, causing this patch to not work.
Use abi.FuncPCABIInternal instead of going through assembly or unsafe.Pointer hacks. For golang#38783
Move amd64-specific definitions from general makefunc.go to amd64-specific makefunc_amd64.go. For golang#38783
It looks like this no longer segfaults as of 1.22.0, the playground link returns a coherent panic message instead. |
Yes, the faulty code was removed shortly after I polished up my patches 😭 I mean, good that there's clean behavior now. Before I touch that code again, I should find out whether the MMU/page aliasing magic I have in mind even works in this context. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Use
reflect.StructOf
with one field with an embedded interface and then attempt to call a method on that interface (with a non-nil value set). https://play.golang.org/p/GwTyV_AFWv6Note that using an embedded struct (not an interface) works fine: https://play.golang.org/p/jVFT3pcw7ia
What did you expect to see?
The function to be called and the result shown: "42".
Or, if this isn't supported, a panic probably.
What did you see instead?
A segfault.
The text was updated successfully, but these errors were encountered: