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