Skip to content

Commit 7b10660

Browse files
committed
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.
1 parent ef93570 commit 7b10660

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

ractor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3163,7 +3163,7 @@ make_shareable_check_shareable(VALUE obj)
31633163
return traverse_cont;
31643164
}
31653165
else {
3166-
rb_raise(rb_eRactorError, "can not make shareable object for %"PRIsVALUE, obj);
3166+
rb_raise(rb_eRactorError, "can not make shareable object for %+"PRIsVALUE, obj);
31673167
}
31683168
}
31693169

test/ruby/test_ractor.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ def test_shareability_of_method_proc
6060
assert_unshareable(x, "can not make shareable object for #<Method: String(Kernel)#itself()>", exception: Ractor::Error)
6161
end
6262

63+
def test_shareability_error_uses_inspect
64+
x = (+"").instance_exec { method(:to_s) }
65+
def x.to_s
66+
raise "this should not be called"
67+
end
68+
assert_unshareable(x, "can not make shareable object for #<Method: String#to_s()>", exception: Ractor::Error)
69+
end
70+
6371
def test_default_thread_group
6472
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
6573
begin;

0 commit comments

Comments
 (0)