From 6b6ab580c9798d564393d6d5fa72a00e5a495665 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Sat, 9 Nov 2024 19:50:07 +0100 Subject: [PATCH] save --- gnovm/tests/files/recover12.gno | 15 +++++++++++++++ gnovm/tests/files/recover13.gno | 15 +++++++++++++++ gnovm/tests/files/recover14.gno | 15 +++++++++++++++ gnovm/tests/files/recover15.gno | 15 +++++++++++++++ gnovm/tests/files/recover16.gno | 14 ++++++++++++++ gnovm/tests/files/recover17.gno | 15 +++++++++++++++ gnovm/tests/files/recover18.gno | 15 +++++++++++++++ gnovm/tests/files/recover19.gno | 15 +++++++++++++++ 8 files changed, 119 insertions(+) create mode 100644 gnovm/tests/files/recover12.gno create mode 100644 gnovm/tests/files/recover13.gno create mode 100644 gnovm/tests/files/recover14.gno create mode 100644 gnovm/tests/files/recover15.gno create mode 100644 gnovm/tests/files/recover16.gno create mode 100644 gnovm/tests/files/recover17.gno create mode 100644 gnovm/tests/files/recover18.gno create mode 100644 gnovm/tests/files/recover19.gno diff --git a/gnovm/tests/files/recover12.gno b/gnovm/tests/files/recover12.gno new file mode 100644 index 00000000000..ab16959adfb --- /dev/null +++ b/gnovm/tests/files/recover12.gno @@ -0,0 +1,15 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + arr := []int{1, 2, 3} + _ = arr[3] // Panics because index 3 is out of bounds +} + +// Output: +// recover: slice index out of bounds: 3 (len=3) diff --git a/gnovm/tests/files/recover13.gno b/gnovm/tests/files/recover13.gno new file mode 100644 index 00000000000..d4b1df10ae5 --- /dev/null +++ b/gnovm/tests/files/recover13.gno @@ -0,0 +1,15 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + arr := []int{1, 2, 3} + _ = arr[-1:] // Panics because of negative index +} + +// Output: +// recover: invalid slice index -1 (index must be non-negative) diff --git a/gnovm/tests/files/recover14.gno b/gnovm/tests/files/recover14.gno new file mode 100644 index 00000000000..30a34ab291a --- /dev/null +++ b/gnovm/tests/files/recover14.gno @@ -0,0 +1,15 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + x, y := 10, 0 + _ = x / y // Panics because of division by zero +} + +// Output: +// recover: division by zero diff --git a/gnovm/tests/files/recover15.gno b/gnovm/tests/files/recover15.gno new file mode 100644 index 00000000000..74ba3ea66a2 --- /dev/null +++ b/gnovm/tests/files/recover15.gno @@ -0,0 +1,15 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + var i interface{} = "hello" + _ = i.(int) // Panics because i holds a string, not an int +} + +// Output: +// recover: string is not of type int diff --git a/gnovm/tests/files/recover16.gno b/gnovm/tests/files/recover16.gno new file mode 100644 index 00000000000..31770f6d469 --- /dev/null +++ b/gnovm/tests/files/recover16.gno @@ -0,0 +1,14 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + _ = make([]int, -1) // Panics because of negative length +} + +// Output: +// recover: len out of range diff --git a/gnovm/tests/files/recover17.gno b/gnovm/tests/files/recover17.gno new file mode 100644 index 00000000000..575801017b3 --- /dev/null +++ b/gnovm/tests/files/recover17.gno @@ -0,0 +1,15 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + str := "hello" + _ = str[10] // Panics because index 10 is out of bounds +} + +// Output: +// recover: index out of range [10] with length 5 diff --git a/gnovm/tests/files/recover18.gno b/gnovm/tests/files/recover18.gno new file mode 100644 index 00000000000..f717e560dd2 --- /dev/null +++ b/gnovm/tests/files/recover18.gno @@ -0,0 +1,15 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + var m map[string]int // nil map + m["key"] = 42 // Panics when trying to assign to a nil map +} + +// Output: +// recover: uninitialized map index diff --git a/gnovm/tests/files/recover19.gno b/gnovm/tests/files/recover19.gno new file mode 100644 index 00000000000..e1f0ff4c3b1 --- /dev/null +++ b/gnovm/tests/files/recover19.gno @@ -0,0 +1,15 @@ +package main + + +func main() { + defer func() { + r := recover() + println("recover:", r) + }() + + var p *int + println(*p) +} + +// Output: +// recover: nil pointer dereference