From 807dd0479267a067e8208a2053b446fa13a2e66f Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Mon, 7 Feb 2022 20:08:50 +0900 Subject: merge revision(s) c79d2e54748f52c5023b0a1ee441561df9826c17: [Backport #18562] Fix TAG_THROW through require [Bug #18562] Previously this was being incorrectly swapped with TAG_RAISE in the next line. This would end up checking the T_IMEMO throw_data to the exception handling (which calls Module#===). This happened to not break existing tests because Module#=== returned false when klass is NULL. This commit handles throw from require correctly by jumping to the tag retaining the TAG_THROW state. --- load.c | 2 +- test/ruby/test_exception.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) --- test/ruby/test_exception.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index c8746359fd..f99bb230a3 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -252,6 +252,27 @@ class TestException < Test::Unit::TestCase } end + def test_catch_throw_in_require_cant_be_rescued + bug18562 = '[ruby-core:107403]' + Tempfile.create(["dep", ".rb"]) {|t| + t.puts("throw :extdep, 42") + t.close + + rescue_all = Class.new(Exception) + def rescue_all.===(_) + raise "should not reach here" + end + + v = assert_throw(:extdep, bug18562) do + require t.path + rescue rescue_all => e + assert(false, "should not reach here") + end + + assert_equal(42, v, bug18562) + } + end + def test_throw_false bug12743 = '[ruby-core:77229] [Bug #12743]' Thread.start { -- cgit v1.2.3