diff options
author | Ayke van Laethem <[email protected]> | 2024-10-31 09:18:32 +0100 |
---|---|---|
committer | Ayke <[email protected]> | 2024-11-01 09:11:38 +0100 |
commit | 449eefdb19c58df9303ee5b9fe62fe18876eb2f9 (patch) | |
tree | 81eda99e6092b6508d5dab27c26774b1ea77b596 /testdata | |
parent | 058f62ac08ace927f01b005e7b0a21b1a41590a7 (diff) | |
download | tinygo-449eefdb19c58df9303ee5b9fe62fe18876eb2f9.tar.gz tinygo-449eefdb19c58df9303ee5b9fe62fe18876eb2f9.zip |
compiler: allow deferred panic
This is rare, but apparently some programs do this:
defer panic("...")
This is emitted in the IR as a builtin function.
Diffstat (limited to 'testdata')
-rw-r--r-- | testdata/recover.go | 15 | ||||
-rw-r--r-- | testdata/recover.txt | 4 |
2 files changed, 19 insertions, 0 deletions
diff --git a/testdata/recover.go b/testdata/recover.go index ced90cfae..c7c02c94a 100644 --- a/testdata/recover.go +++ b/testdata/recover.go @@ -19,6 +19,9 @@ func main() { println("\n# panic replace") panicReplace() + + println("\n# defer panic") + deferPanic() } func recoverSimple() { @@ -89,6 +92,18 @@ func panicReplace() { panic("panic 1") } +func deferPanic() { + defer func() { + printitf("recovered from deferred call:", recover()) + }() + + // This recover should not do anything. + defer recover() + + defer panic("deferred panic") + println("defer panic") +} + func printitf(msg string, itf interface{}) { switch itf := itf.(type) { case string: diff --git a/testdata/recover.txt b/testdata/recover.txt index d27649855..357505881 100644 --- a/testdata/recover.txt +++ b/testdata/recover.txt @@ -23,3 +23,7 @@ recovered: panic panic 1 panic 2 recovered: panic 2 + +# defer panic +defer panic +recovered from deferred call: deferred panic |