GoPLS Viewer

Home|gopls/go/pointer/testdata/panic.go
1//go:build ignore
2// +build ignore
3
4package main
5
6// Test of value flow from panic() to recover().
7// We model them as stores/loads of a global location.
8// We ignore concrete panic types originating from the runtime.
9
10var someval int
11
12type myPanic struct{}
13
14func f(int) {}
15
16func g() string { return "" }
17
18func deadcode() {
19    panic(123// not reached
20}
21
22func main() {
23    switch someval {
24    case 0:
25        panic("oops")
26    case 1:
27        panic(myPanic{})
28    case 2:
29        panic(f)
30    case 3:
31        panic(g)
32    }
33    ex := recover()
34    print(ex)                 // @types myPanic | string | func(int) | func() string
35    print(ex.(func(int)))     // @pointsto command-line-arguments.f
36    print(ex.(func() string)) // @pointsto command-line-arguments.g
37}
38
MembersX
main.BlockStmt.ex
someval
myPanic
deadcode
Members
X