diff options
| -rw-r--r-- | src/codegen.c | 14 | ||||
| -rw-r--r-- | test/t/exception.rb | 10 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/codegen.c b/src/codegen.c index ce9967f89..59fde4cb8 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1570,15 +1570,20 @@ codegen(codegen_scope *s, node *tree, int val) break; case NODE_RETURN: - codegen(s, tree, VAL); - pop(); + if (tree) { + codegen(s, tree, VAL); + pop(); + } + else { + genop(s, MKOP_A(OP_LOADNIL, cursp())); + } if (s->loop) { genop(s, MKOP_AB(OP_RETURN, cursp(), OP_R_RETURN)); } else { genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); } - push(); + if (val) push(); break; case NODE_YIELD: @@ -1630,6 +1635,9 @@ codegen(codegen_scope *s, node *tree, int val) codegen(s, tree, VAL); pop(); } + else { + genop(s, MKOP_A(OP_LOADNIL, cursp())); + } genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); } if (val) push(); diff --git a/test/t/exception.rb b/test/t/exception.rb index 663c8f337..7ecc51fa8 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -321,19 +321,19 @@ end # very deeply recursive function that stil returns albeit very deeply so $test_infinite_recursion = 0 -TEST_INFINITE_RECURSION_MAX = 100000 +TEST_INFINITE_RECURSION_MAX = 1000000 def test_infinite_recursion $test_infinite_recursion += 1 if $test_infinite_recursion > TEST_INFINITE_RECURSION_MAX - return $test_infinite_recursion + return $test_infinite_recursion end - test_infinite_recursion + test_infinite_recursion end assert('Infinite recursion should result in an exception being raised') do - a = begin + a = begin test_infinite_recursion - rescue + rescue :ok end # OK if an exception was caught, otherwise a number will be stored in a |
