Skip to content

Commit

Permalink
Include the first constant name into Ractor::IsolationError message
Browse files Browse the repository at this point in the history
If lhs of assignment is top-level constant reference, the first
constant name is omitted from error message.
This commit fixes it.

```
# shareable_constant_value: literal
::C = ["Not " + "shareable"]

# Before
# => cannot assign unshareable object to  (Ractor::IsolationError)

# After
# => cannot assign unshareable object to ::C (Ractor::IsolationError)
```
  • Loading branch information
yui-knk committed Feb 10, 2024
1 parent e7b0a01 commit bf72cb8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions ruby_parser.c
Expand Up @@ -1060,6 +1060,7 @@ rb_node_const_decl_val(const NODE *node)
}
else if (n && nd_type_p(n, NODE_COLON3)) {
// ::Const::Name
rb_ary_push(path, rb_id2str(RNODE_COLON3(n)->nd_mid));
rb_ary_push(path, rb_str_new(0, 0));
}
else {
Expand Down
27 changes: 26 additions & 1 deletion test/ruby/test_parse.rb
Expand Up @@ -1537,12 +1537,37 @@ class X
end
def test_shareable_constant_value_unshareable_literal
assert_raise_separately(Ractor::IsolationError, /unshareable/,
assert_raise_separately(Ractor::IsolationError, /unshareable object to C/,
"#{<<~"begin;"}\n#{<<~'end;'}")
begin;
# shareable_constant_value: literal
C = ["Not " + "shareable"]
end;
assert_raise_separately(Ractor::IsolationError, /unshareable object to B::C/,
"#{<<~"begin;"}\n#{<<~'end;'}")
begin;
# shareable_constant_value: literal
B = Class.new
B::C = ["Not " + "shareable"]
end;
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
assert_raise_with_message(Ractor::IsolationError, /unshareable object to ::C/) do
# shareable_constant_value: literal
::C = ["Not " + "shareable"]
end
end;
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
assert_raise_with_message(Ractor::IsolationError, /unshareable object to ::B::C/) do
# shareable_constant_value: literal
::B = Class.new
::B::C = ["Not " + "shareable"]
end
end;
end
def test_shareable_constant_value_nonliteral
Expand Down

0 comments on commit bf72cb8

Please sign in to comment.