merge revision(s) 9c94db7cfc584e982a6449b72e58a1cf25024177,fe4d906f5fbacbe6e9267af3bd3503339bad63a9: [Backport #19774]

Add tests for `return` in `BEGIN` and `END` blocks

	---
	 spec/ruby/language/return_spec.rb | 15 +++++++++++++++
	 test/ruby/test_syntax.rb          |  1 +
	 2 files changed, 16 insertions(+)

	[Bug #19774] Fix segfault at `return` in `END`

	---
	 eval_error.c             | 7 ++++++-
	 test/ruby/test_syntax.rb | 5 +++++
	 2 files changed, 11 insertions(+), 1 deletion(-)
This commit is contained in:
nagachika 2023-07-22 14:01:55 +09:00
Родитель 65d294ad01
Коммит b97a744a37
4 изменённых файлов: 28 добавлений и 2 удалений

Просмотреть файл

@ -455,7 +455,12 @@ exiting_split(VALUE errinfo, volatile int *exitcode, volatile int *sigstatus)
if (NIL_P(errinfo)) return 0;
if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
if (THROW_DATA_P(errinfo)) {
int throw_state = ((const struct vm_throw_data *)errinfo)->throw_state;
ex = throw_state & VM_THROW_STATE_MASK;
result |= EXITING_WITH_STATUS;
}
else if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
ex = sysexit_status(errinfo);
result |= EXITING_WITH_STATUS;
}

Просмотреть файл

@ -435,6 +435,21 @@ describe "The return keyword" do
end
end
describe "within BEGIN" do
it "is allowed" do
File.write(@filename, <<-END_OF_CODE)
BEGIN {
ScratchPad << "before call"
return
ScratchPad << "after call"
}
END_OF_CODE
load @filename
ScratchPad.recorded.should == ["before call"]
end
end
describe "file loading" do
it "stops file loading and execution" do
File.write(@filename, <<-END_OF_CODE)

Просмотреть файл

@ -1369,6 +1369,8 @@ eom
begin raise; ensure return; end and self
nil&defined?0--begin e=no_method_error(); return; 0;end
return puts('ignored') #=> ignored
BEGIN {return}
END {return if false}
end;
.split(/\n/).map {|s|[(line+=1), *s.split(/#=> /, 2)]}
failed = proc do |n, s|
@ -1406,6 +1408,10 @@ eom
assert_in_out_err(['-e', 'class TestSyntax; proc{ return }.call; end'], "", [], /^-e:1:.*unexpected return \(LocalJumpError\)/)
end
def test_return_in_END
assert_normal_exit('END {return}')
end
def test_syntax_error_in_rescue
bug12613 = '[ruby-core:76531] [Bug #12613]'
assert_syntax_error("#{<<-"begin;"}\n#{<<-"end;"}", /Invalid retry/, bug12613)

Просмотреть файл

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 2
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 102
#define RUBY_PATCHLEVEL 103
#include "ruby/version.h"
#include "ruby/internal/abi.h"