$ cat /tmp/x.go
package main
func f(x int) int {
return x + 1
}
func main() {
var v []int
println("%d\n", f(v[0]))
}
$ go run /tmp/x.go
panic: runtime error: index out of range
goroutine 1 [running]:
main.f(...)
/tmp/x.go:9
main.main()
/tmp/x.go:9 +0x11
exit status 2
At first glance I thought the line number was wrong, since main.f and main.main are not both on line 9.
But in fact the bug is that main.f shows up at all. The index panic happens preparing the argument to f, not in the inlined copy of f. The line number is correct - v[0] is on line 9. What's wrong is that main.f shows up at all. It should not.
/cc @davidlazar @aclements
At first glance I thought the line number was wrong, since main.f and main.main are not both on line 9.
But in fact the bug is that main.f shows up at all. The index panic happens preparing the argument to f, not in the inlined copy of f. The line number is correct - v[0] is on line 9. What's wrong is that main.f shows up at all. It should not.
/cc @davidlazar @aclements