summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2020-06-10 18:44:52 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2020-06-11 14:46:08 -0400
commite100fcbdd1e81c23e3b4c87964aff210232903a8 (patch)
tree500c79c58a55359574d3008a8d9a0dce9cfe5492 /test/ruby
parent631c01f5ae64d1034ec719c9f97da906e7f508b3 (diff)
Prohibit setting class variable on frozen module through inheritance
Setting class varibles goes through the ancestor list which can contain iclasses. Iclasses share a lot of information with the module they are made from, but not the frozen status. Check the frozen status of the module instead of the iclass.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3203
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_variable.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb
index b053e11607..685a06226f 100644
--- a/test/ruby/test_variable.rb
+++ b/test/ruby/test_variable.rb
@@ -35,6 +35,16 @@ class TestVariable < Test::Unit::TestCase
end
end
+ def test_setting_class_variable_on_module_through_inheritance
+ mod = Module.new
+ mod.class_variable_set(:@@foo, 1)
+ mod.freeze
+ c = Class.new { include(mod) }
+ assert_raise(FrozenError) { c.class_variable_set(:@@foo, 2) }
+ assert_raise(FrozenError) { c.class_eval("@@foo = 2") }
+ assert_equal(1, c.class_variable_get(:@@foo))
+ end
+
def test_singleton_class_included_class_variable
c = Class.new
c.extend(Olympians)