diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2019-08-10 17:32:49 -0400 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-08-14 17:13:28 +0900 |
commit | c8f97596b7dd6ffbeb98970f9cc664b0a8a2336e (patch) | |
tree | 34814f4debc980da7aec3f3c6ab05e154a35c09e /test/ruby/test_module.rb | |
parent | 1cffd5b4f0b88669bc2daff025ab0b1650961a43 (diff) |
Don't accidentally name anonymous module/class
b00f280d4b9569e7153365d7e1c522b3d6b3c6cf introduced
an accidental behavior change in that defining a module/class under
`m` gives `m` a name when `m` is anonymous.
`ruby -ve 'Module.new { class self::A; end; p name }'` outputs a name
similar to `Module#inspect` when it should output `nil` like in Ruby
2.6.x.
* variable.c: Use `make_temporary_path` instead of `save_temporary_path`
when getting the name of the parent module.
* variable.c (rb_set_class_path): Delegate to `rb_set_class_path_string`
instead of duplicating the logic.
[Bug #16097]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2337
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r-- | test/ruby/test_module.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index b8d6ffb19d..d56e63e4be 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -565,6 +565,24 @@ class TestModule < Test::Unit::TestCase assert_equal("TestModule::User", User.name) end + def test_accidental_singleton_naming_with_module + o = Object.new + assert_nil(o.singleton_class.name) + class << o + module Hi; end + end + assert_nil(o.singleton_class.name) + end + + def test_accidental_singleton_naming_with_class + o = Object.new + assert_nil(o.singleton_class.name) + class << o + class Hi; end + end + assert_nil(o.singleton_class.name) + end + def test_classpath m = Module.new n = Module.new |