-
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: FuncForPC FileLine returns autogenerated instead of actual path #51774
Comments
cc @golang/runtime |
Bisects to CL 388794 (I was curious). |
CC @cherrymui |
I'm not really sure what the right answer to be here. Technically this function is indeed autogenerated, as it is a closure capturing the receiver. This is also seen in the synthetic name ( We may be able to restore the old behavior, but I'm not sure that is best. If we want to give the location of the definition, perhaps we also want to give the original method name instead of the synthetic If you use the method that does not capture the receiver, like
It prints the actual line number. Would that be okay? Thanks. |
In my case using If there is a workaround or a more reliable solution to resolve arbitrary function into a place of origin in code, I would be happy to use it. |
This is also affecting https://github.com/go-chai/chai, which is a http router extension that generates a swagger spec based on the new generics. It used to work with go1.18beta2. The way I use it is chai.Get(r, "/{id}", controller.SomeHandler) runtime.FuncForPC then finds the file and line where SomeHandler is defined so it could use the AST and parse some swagger annotations from the comment above that function. Now it returns I wonder how Delve figures out the line numbers of functions when debugging and if it can be used for this sort of thing. |
@cherrymui @randall77 What is the current status here? This issue is currently in the 1.19 milestone. Should it move to 1.20? To Backlog? Thanks. |
I'd think it behaves as intended, in the same spirit of #52809 . The method value is a compiler-generated closure, so it actually has a synthetic name and file path. |
The method value is a wrapper which immediately calls the actual method function, which has a real name and file path. At run time, when debugging you'll debug the actual function, not the wrapper. Similarly, For |
I'm not sure I fully understand technical implications here, but from my end-user perspective I see a breaking, backwards incompatible change that affects existing code. Lack of workaround makes it worse. I'd be happy to use any other way to find out which file:line is the origin of closure. Using Instrumenting closures to retrieve #52809 seems related, however it does not say anything about file:line. Hopefully a compromise can be found, thanks. |
Unlike #52809 which is about the function name, we could report a reasonable file/line position, I think. The whole method would have the file/line of the declaration of the method it is wrapping. In fact even the name we might be able to slice off a trailing |
I'm also banging my head against a wall trying to figure out a workaround for this, as our code for autogenerating our REST API documentation broke with the upgrade to 1.18. Is there any way to access the original function that the |
Change https://go.dev/cl/416455 mentions this issue: |
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?
I was getting file and line of struct method.
https://go.dev/play/p/VFs8FKAkTLf
What did you expect to see?
What did you see instead?
The issue is reproducible with
go1.18
andgotip
, howevergo1.18rc1
and below (go1.17
) works as expected.The text was updated successfully, but these errors were encountered: