.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.1.1-0.20210319172145-bda8f5cee399 / go / pointer / testdata / panic.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.1-0.20210319172145-bda8f5cee399/go/pointer/testdata/panic.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.1-0.20210319172145-bda8f5cee399/go/pointer/testdata/panic.go
new file mode 100644 (file)
index 0000000..ee8a766
--- /dev/null
@@ -0,0 +1,36 @@
+// +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)                 // @types myPanic | string | func(int) | func() string
+       print(ex.(func(int)))     // @pointsto main.f
+       print(ex.(func() string)) // @pointsto main.g
+}