mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
compiler, runtime: implement recoverable divide-by-zero panic
This gets the math/bits and go/constant package tests to pass. Unfortunately, this also has a binary size impact of around 150-200 bytes in many cases. I'm a bit on the edge on whether this is worth it, since it's mostly used for getting package tests to work. But at the same time, having working package tests is very valuable.
This commit is contained in:
Vendored
+13
@@ -30,6 +30,9 @@ func main() {
|
||||
println("\n# defer panic")
|
||||
deferPanic()
|
||||
|
||||
println("\n# runtime panics")
|
||||
runtimePanicDivByZero(1, 0)
|
||||
|
||||
println("\n# runtime.Goexit")
|
||||
runtimeGoexit()
|
||||
}
|
||||
@@ -114,6 +117,16 @@ func deferPanic() {
|
||||
println("defer panic")
|
||||
}
|
||||
|
||||
func runtimePanicDivByZero(a, b int) int {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
println("recovered:", err)
|
||||
}
|
||||
}()
|
||||
|
||||
return a / b
|
||||
}
|
||||
|
||||
func runtimeGoexit() {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user