Source file
test/fixedbugs/issue19799.go
1
2
3
4
5
6
7 package main
8
9 import (
10 "os"
11 "runtime"
12 )
13
14 func foo(x int) int {
15 return x + 1
16 }
17
18 func test() {
19 defer func() {
20 if r := recover(); r != nil {
21 pcs := make([]uintptr, 10)
22 n := runtime.Callers(0, pcs)
23 pcs = pcs[:n]
24 frames := runtime.CallersFrames(pcs)
25 for {
26 f, more := frames.Next()
27 if f.Function == "main.foo" {
28 println("did not expect to see call to foo in stack trace")
29 os.Exit(1)
30 }
31 if !more {
32 break
33 }
34 }
35 }
36 }()
37 var v []int
38 foo(v[0])
39 }
40
41 func bar(x ...int) int {
42 return x[0] + 1
43 }
44
45 func testVariadic() {
46 defer func() {
47 if r := recover(); r != nil {
48 pcs := make([]uintptr, 10)
49 n := runtime.Callers(0, pcs)
50 pcs = pcs[:n]
51 frames := runtime.CallersFrames(pcs)
52 for {
53 f, more := frames.Next()
54 if f.Function == "main.bar" {
55 println("did not expect to see call to bar in stack trace")
56 os.Exit(1)
57 }
58 if !more {
59 break
60 }
61 }
62 }
63 }()
64 var v []int
65 bar(v[0])
66 }
67
68 func main() {
69 test()
70 testVariadic()
71 }
72
View as plain text