Use rb_inspect for Ractor error

Previously the object was used directly, which calls `to_s` if defined.
We should use rb_inspect to get a value suitable for display to the
programmer.
This commit is contained in:
John Hawthorn 2025-05-20 17:28:30 -07:00
parent ef935705cf
commit 7b10660974
Notes: git 2025-05-21 19:23:27 +00:00
2 changed files with 9 additions and 1 deletions

View File

@ -3163,7 +3163,7 @@ make_shareable_check_shareable(VALUE obj)
return traverse_cont;
}
else {
rb_raise(rb_eRactorError, "can not make shareable object for %"PRIsVALUE, obj);
rb_raise(rb_eRactorError, "can not make shareable object for %+"PRIsVALUE, obj);
}
}

View File

@ -60,6 +60,14 @@ class TestRactor < Test::Unit::TestCase
assert_unshareable(x, "can not make shareable object for #<Method: String(Kernel)#itself()>", exception: Ractor::Error)
end
def test_shareability_error_uses_inspect
x = (+"").instance_exec { method(:to_s) }
def x.to_s
raise "this should not be called"
end
assert_unshareable(x, "can not make shareable object for #<Method: String#to_s()>", exception: Ractor::Error)
end
def test_default_thread_group
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;