Skip to content

Commit c8cce99

Browse files
committed
Show Hash#default_proc and Hash#default differently
1 parent 2d6912e commit c8cce99

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

bootstraptest/test_ractor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,10 +986,10 @@ def self.fstr = @fstr
986986
a + b + c + d + e + f
987987
}
988988

989-
assert_equal " from hash default value\n" \
989+
assert_equal " from hash default proc\n" \
990990
" from instance variable @ivar\n" \
991991
" from block self #<Foo @ivar={}>\n" \
992-
" from hash default value\n" \
992+
" from hash default proc\n" \
993993
" from instance variable @ivar\n" \
994994
" from instance variable @foo", %q{
995995
class Foo

ractor.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,11 @@ obj_traverse_i(VALUE obj, struct obj_traverse_data *data)
13471347
{
13481348
const VALUE ifnone = RHASH_IFNONE(obj);
13491349
if (obj_traverse_i(ifnone, data)) {
1350-
rb_ractor_error_chain_append(data->chain, "\n from hash default value");
1350+
if (RB_FL_TEST_RAW(obj, RHASH_PROC_DEFAULT)) {
1351+
rb_ractor_error_chain_append(data->chain, "\n from hash default proc");
1352+
} else {
1353+
rb_ractor_error_chain_append(data->chain, "\n from hash default value");
1354+
}
13511355
return 1;
13521356
}
13531357

test/ruby/test_ractor.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,14 @@ def test_error_includes_hash_unshareable_key
234234
assert_unshareable({ -> {} => true }, /from hash key #<Proc:0x[[:xdigit:]]+ #{__FILE__}:#{__LINE__}/)
235235
end
236236

237-
def test_error_includes_hash_default
237+
def test_error_includes_hash_default_proc
238238
h = Hash.new {}
239-
assert_unshareable(h, /from hash default value/)
239+
assert_unshareable(h, /from hash default proc/)
240+
end
241+
242+
def test_error_includes_hash_default_value
243+
h = Hash.new(Mutex.new)
244+
assert_unshareable(h, /from hash default value/, exception: Ractor::Error)
240245
end
241246

242247
def test_error_includes_struct_member
@@ -272,7 +277,7 @@ def test_error_for_module_instance_variable
272277
$!
273278
end.value
274279
assert_kind_of Ractor::IsolationError, e
275-
assert_match(/from hash default value/, e.message)
280+
assert_match(/from hash default proc/, e.message)
276281
RUBY
277282
end
278283

@@ -288,7 +293,7 @@ module ModuleWithUnshareableConstant
288293
$!
289294
end.value
290295
assert_kind_of(Ractor::IsolationError, e)
291-
assert_match(/from hash default value/, e.message)
296+
assert_match(/from hash default proc/, e.message)
292297
RUBY
293298
end
294299

0 commit comments

Comments
 (0)