You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ n /tmp/x.go
1 package main
2
3 import "runtime"
4
5 func main() {
6 var file string
7 var line int
8 func() {
9 defer func() {
10 _, file, line, _ = runtime.Caller(1)
11 }()
12 }()
13 println(file, line)
14 }
$ go1.4 run /tmp/x.go
/tmp/x.go 12
$ go1.5 run /tmp/x.go
/tmp/x.go 12
$ go1.6 run /tmp/x.go
/tmp/x.go 12
$ go run /tmp/x.go
/tmp/x.go 8
$
The file and line of the caller of a deferred function should appear to be the end of that function or the explicit return statement that triggered the deferred function calls. It has regressed since Go 1.6 was cut to report the beginning of the function. We should fix this and add a test.
It looks like explicit returns are handled correctly and that only the implicit return inserted at the end of the function is generated with incorrect line information:
$ n /tmp/x.go
1 package main
2
3 import (
4 "os"
5 "runtime"
6 )
7
8 func main() {
9 var file string
10 var line int
11 func() {
12 defer func() {
13 _, file, line, _ = runtime.Caller(1)
14 }()
15 if len(os.Args) > 1 {
16 return
17 }
18 return
19 }()
20 println(file, line)
21 }
$ go1.6 run /tmp/x.go
/tmp/x.go 18
$ go1.6 run /tmp/x.go -
/tmp/x.go 16
$ go run /tmp/x.go
/tmp/x.go 18
$ go run /tmp/x.go -
/tmp/x.go 16
$
The file and line of the caller of a deferred function should appear to be the end of that function or the explicit return statement that triggered the deferred function calls. It has regressed since Go 1.6 was cut to report the beginning of the function. We should fix this and add a test.
It looks like explicit returns are handled correctly and that only the implicit return inserted at the end of the function is generated with incorrect line information:
/cc @randall77 @dr2chase
The text was updated successfully, but these errors were encountered: