Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
runtime: runtime.Caller() => "<autogenerated>" #16723
I was playing with a method that wants to print the file:line of the caller.
It looks like this has to do with being an interface method: https://play.golang.org/p/I5XPdWR_O0
Is there a generic way to get the actual caller, safely, in all cases?
go version go1.6.1 linux/amd64
The interface call calls a wrapper which calls the direct call. The wrapper is auto-generated. Whether you consider the wrapper the "actual caller" depends on your point of view I guess.
You can avoid the wrappers by defining the methods on *fooMether instead of fooMether.
I'm not sure what to do about this in the mean time. We'll have to look at callers again when we look at non-leaf inlining this winter. Maybe then would be a good time to revisit the behavior of runtime.Caller with respect to eliding autogenerated wrappers.
Bumping to Go 1.10 since this isn't a regression and there's some concern that this may affect code that's already compensating for this. The general consensus is that this should be fixed, however, so that the traceback APIs reflect the programmer's model of the stack rather than the implementation's model (like how the skip parameter now expands out inlined frames to match the programmer's model).
Early in the 1.10 cycle we should put in something like the CLs I posted above.