-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: deferred log prints wrong line number #24839
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
Comments
See if this simpler example demonstrates the same problem: EDIT: it seems that the line of the first occurrence of the method value is used, see: |
@pam4 Thanks; yes, your code describes the same problem. |
This is interesting. Using gccgo does indeed log line 61. But using the gc compiler all the way back to 1.0.3 logs line 20. |
Shorter test case. The first line of output should show line 19, not line 15. package main
import (
"log"
"os"
)
var lg = log.New(os.Stdout, "x: ", log.Lshortfile)
func main() {
F()
}
func F() {
defer lg.Println(trace(lg.Println))
}
func trace(f func(v ...interface{})) interface{} {
f("calling")
return "called"
} |
Even shorter test case not even using log or defer
|
This issue is definitely a duplicate of #24488. Also the title is misleading because there is nothing specific about defer or the log package (except for the fact that the log package makes use of stack information). The problem is that method values end up in the stack trace, even though they are not function calls. But oddly, the method value that ends up in the stack trace is not necessarily the one that leads to the function call; please take a look at this example: https://play.golang.org/p/RKQj5JcxvJH I would prefer method values not to end up in the stack trace at all (unless they are actually called) because some of my code depends on it. EDIT: the unexpected frames may represent compiler generated wrapper methods, see #16723. |
Closing as dup. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.10.1 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?What did you do?
*Logger.Println
withlog.Lshortfile
flag, logs the wrong line number - Go code to reproduce this.And the output is:
What did you expect to see?
The three lines of output which report line number
20
should be showing line number61
.What did you see instead?
Line numbers logged by
*Logger.Println
are not correct.The text was updated successfully, but these errors were encountered: