summaryrefslogtreecommitdiffstats
path: root/llgo/third_party/gotools/go/ssa/interp/testdata/recover.go
blob: b5600522633a8b5fe4ee0720a7e4b2d47329b6ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

// Tests of panic/recover.

import "fmt"

func fortyTwo() (r int) {
	r = 42
	// The next two statements simulate a 'return' statement.
	defer func() { recover() }()
	panic(nil)
}

func zero() int {
	defer func() { recover() }()
	panic(1)
}

func zeroEmpty() (int, string) {
	defer func() { recover() }()
	panic(1)
}

func main() {
	if r := fortyTwo(); r != 42 {
		panic(r)
	}
	if r := zero(); r != 0 {
		panic(r)
	}
	if r, s := zeroEmpty(); r != 0 || s != "" {
		panic(fmt.Sprint(r, s))
	}
}
OpenPOWER on IntegriCloud