Feature #4840 ยป 0001-compile.c-toplevel-return.patch
compile.c | ||
---|---|---|
4569 | 4569 |
rb_iseq_t *is = iseq; |
4570 | 4570 | |
4571 | 4571 |
if (is) { |
4572 |
if (is->type == ISEQ_TYPE_TOP) { |
|
4573 |
COMPILE_ERROR((ERROR_ARGS "Invalid return")); |
|
4572 |
if (is->type == ISEQ_TYPE_TOP || is->type == ISEQ_TYPE_MAIN) { |
|
4573 |
ADD_INSN(ret, line, putnil); |
|
4574 |
ADD_INSN(ret, line, leave); |
|
4574 | 4575 |
} |
4575 | 4576 |
else { |
4576 | 4577 |
LABEL *splabel = 0; |
test/ruby/test_syntax.rb | ||
---|---|---|
363 | 363 |
assert_constant_reassignment_toplevel("11", "+", %w[53], already) |
364 | 364 |
end |
365 | 365 | |
366 |
def test_return_toplevel |
|
367 |
feature4840 = '[ruby-core:36785] [Feature #4840]' |
|
368 |
assert_ruby_status([], "return; raise", feature4840) |
|
369 |
assert_ruby_status([], "begin return; resucue SystemExit; exit false; end", feature4840) |
|
370 |
assert_ruby_status([], "begin return; ensure exit false; end", feature4840) |
|
371 |
assert_ruby_status([], "return false; raise", feature4840) |
|
372 |
assert_ruby_status([], "return 1; raise", feature4840) |
|
373 |
end |
|
374 | ||
366 | 375 |
private |
367 | 376 | |
368 | 377 |
def not_label(x) @result = x; @not_label ||= nil end |
369 |
- |