Closed
Description
Using go1.6
Consider the following:
package main
func Foo(b bool) {
if b {
panic("ha")
}
}
func main() { // Line 9
defer Foo(false) // Line 10
defer Foo(true) // Line 11
defer Foo(false) // Line 12
defer Foo(false) // Line 13
} // Line 14
Currently, this prints:
panic: ha
goroutine 1 [running]:
panic(0x94e60, 0x1030a040)
/usr/local/go/src/runtime/panic.go:481 +0x700
main.Foo(0x10327f01, 0xb4a00)
/tmp/sandbox118729948/main.go:5 +0x80
main.main()
/tmp/sandbox118729948/main.go:14 +0x13b
However, the stack trace reports that the panic occurs at Line 14 of main, which is technically correct since it is at the end of the function and now executing deferred functions. However, it is ambiguous exactly which of the calls to Foo was part of the real stack trace.
Any thoughts on having the printed line number be the line number where the defer occurred? In this example, it would be Line 11.