-
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
runtime: Caller
can return <autogenerated>
as filename when called from a global variable
#64520
Comments
I can still reproduce with |
I'm not sure how we would fix this. There's no file for this kind of init function (the kind that contains initialization code for all the global variables, not the kind the user declared with I guess we could generate an init function per file instead of per package. But that doesn't really work either, as initialization order can jump back and forth between files. So really we'd need one init function per global variable to be able to accurately give a file name. (Maybe that's not so horrible? Probably we could coalesce in the common case. It adds complexity, but maybe we'd have to do so anyway if we ever solve #14840?) Note that you can use |
Thanks for the reply ! Indeed when you start looking into the internals it becomes much less obvious that this is a bug 😄 From my side we stopped relying on this behavior when we noticed it changed, so I won't push for this to be fixed, up to you ! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No, the issue appeared with 88cb17e (unreleased).
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When using the current dev version of Go,
runtime.Caller
can return<autogenerated>
as caller filename, instead of the actual caller filename.Minimal reproducible example can be found on https://github.com/pgimalac/gist/tree/go-runtime-caller-filename-autogenerated (I could not reduce it to a single file, but it's rather small as it is).
The example declares a global variable which indirectly calls
runtime.Caller
, which returns<autogenerated>
instead of the actual filename.A main function prints an error with the returned filename if it doesn't contain
package1
. It can run withgo run main.go
.If this is not considered a bug, the documentation should make it clear that
runtime.Caller
can return something else when called from a global variable.What did you expect to see?
runtime.Caller
should return<root>/mypackage1/myfile.go
.What did you see instead?
runtime.Caller
returns<autogenerated>
.The text was updated successfully, but these errors were encountered: