mirror of
https://github.com/golang/go
synced 2024-11-19 00:04:40 -07:00
6643abb26c
Suggested reading order: - doc.go - api.go, analysis.go, callgraph.go, labels.go - print.go, util.go - gen.go - solve.go - pointer_test.go, testdata/* - intrinsics.go (none are implemented yet) R=dannyb, gri, crawshaw, 0xjnml CC=golang-dev https://golang.org/cl/10618043
37 lines
662 B
Go
37 lines
662 B
Go
// +build ignore
|
|
|
|
package main
|
|
|
|
// Test of value flow from panic() to recover().
|
|
// We model them as stores/loads of a global location.
|
|
// We ignore concrete panic types originating from the runtime.
|
|
|
|
var someval int
|
|
|
|
type myPanic struct{}
|
|
|
|
func f(int) {}
|
|
|
|
func g() string { return "" }
|
|
|
|
func deadcode() {
|
|
panic(123) // not reached
|
|
}
|
|
|
|
func main() {
|
|
switch someval {
|
|
case 0:
|
|
panic("oops")
|
|
case 1:
|
|
panic(myPanic{})
|
|
case 2:
|
|
panic(f)
|
|
case 3:
|
|
panic(g)
|
|
}
|
|
ex := recover()
|
|
print(ex) // @concrete myPanic | string | func(int) | func() string
|
|
print(ex.(func(int))) // @pointsto main.f
|
|
print(ex.(func() string)) // @pointsto main.g
|
|
}
|