| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2017 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// The compiler was panicking on the wrong line number, where |
| 8 |
// the panic was occurring in an inlined call. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
import ( |
| 13 |
"runtime/debug" |
| 14 |
"strings" |
| 15 |
) |
| 16 |
|
| 17 |
type Wrapper struct { |
| 18 |
a []int |
| 19 |
} |
| 20 |
|
| 21 |
func (w Wrapper) Get(i int) int { |
| 22 |
return w.a[i] |
| 23 |
} |
| 24 |
|
| 25 |
func main() { |
| 26 |
defer func() { |
| 27 |
e := recover() |
| 28 |
if e == nil { |
| 29 |
panic("bounds check didn't fail") |
| 30 |
} |
| 31 |
stk := string(debug.Stack()) |
| 32 |
if !strings.Contains(stk, "issue22083.go:40") { |
| 33 |
panic("wrong stack trace: " + stk) |
| 34 |
} |
| 35 |
}() |
| 36 |
foo := Wrapper{a: []int{0, 1, 2}} |
| 37 |
_ = foo.Get(0) |
| 38 |
_ = foo.Get(1) |
| 39 |
_ = foo.Get(2) |
| 40 |
_ = foo.Get(3) // stack trace should mention this line |
| 41 |
} |