diff options
author | Koichi Sasada <ko1@atdot.net> | 2023-04-19 11:40:16 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2023-04-19 14:53:56 +0900 |
commit | 628e432739e1d2578d357420aa652a97eb8c2649 (patch) | |
tree | 6916e2f32267e3b80c17e98ca03b08b46a9d773b /test | |
parent | 62781d479b5fd5a506bb6de602edefa797551a82 (diff) | |
download | ruby-628e432739e1d2578d357420aa652a97eb8c2649.tar.gz |
fix `NameError` message
The following code produces two NameErrors respectively
and they are independent, but the second one can show
`private constant` message because of first NameError.
```ruby
class C
class PrivateClass; end
private_constant :PrivateClass
end
begin
eval('class C::PrivateClass; end')
rescue => e
p e
end
begin
Object.const_get 'Foo'
rescue => e
p e
end
#<NameError: private constant C::PrivateClass referenced>
#<NameError: private constant C::Foo referenced>
#=> should be #<NameError: uninitialized constant Foo>
```
It fails the test-all tests with
`make test-all TESTS='ruby/class ruby/parse --seed=58891 -v`.
The reason is clear miss from https://github.com/ruby/ruby/commit/7387c08373a
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_class.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 5086e60398..d1d196c9af 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -355,6 +355,17 @@ class TestClass < Test::Unit::TestCase assert_equal(42, PrivateClass.new.foo) end + def test_private_const_access + assert_raise_with_message NameError, /uninitialized/ do + begin + eval('class ::TestClass::PrivateClass; end') + rescue NameError => e + end + + Object.const_get "NOT_AVAILABLE_CONST_NAME_#{__LINE__}" + end + end + StrClone = String.clone Class.new(StrClone) |