Skip to content

Commit dfa9eb5

Browse files
committed
variable.c: fail if frozen
* variable.c (set_const_visibility): fail if the class/module is frozen. [ruby-core:70828] [Bug ruby#11532] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent c3a4873 commit dfa9eb5

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Wed Sep 16 20:39:26 2015 Nobuyoshi Nakada <[email protected]>
2+
3+
* variable.c (set_const_visibility): fail if the class/module is
4+
frozen. [ruby-core:70828] [Bug #11532]
5+
16
Wed Sep 16 17:16:43 2015 Nobuyoshi Nakada <[email protected]>
27

38
* vm_core.h (ENABLE_VM_OBJSPACE): enable per-VM object space on

test/ruby/test_module.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,25 @@ class TestModule::PrivateConstantReopen::PRIVATE_CONSTANT
19481948
end
19491949
end
19501950

1951+
def test_frozen_visibility
1952+
bug11532 = '[ruby-core:70828] [Bug #11532]'
1953+
1954+
c = Class.new {const_set(:A, 1)}.freeze
1955+
assert_raise_with_message(RuntimeError, /frozen class/, bug11532) {
1956+
c.class_eval {private_constant :A}
1957+
}
1958+
1959+
c = Class.new {const_set(:A, 1); private_constant :A}.freeze
1960+
assert_raise_with_message(RuntimeError, /frozen class/, bug11532) {
1961+
c.class_eval {public_constant :A}
1962+
}
1963+
1964+
c = Class.new {const_set(:A, 1)}.freeze
1965+
assert_raise_with_message(RuntimeError, /frozen class/, bug11532) {
1966+
c.class_eval {deprecate_constant :A}
1967+
}
1968+
end
1969+
19511970
def test_singleton_class_ancestors
19521971
feature8035 = '[ruby-core:53171]'
19531972
obj = Object.new

variable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,7 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv,
26012601
rb_const_entry_t *ce;
26022602
ID id;
26032603

2604+
rb_frozen_class_p(mod);
26042605
if (argc == 0) {
26052606
rb_warning("%"PRIsVALUE" with no argument is just ignored",
26062607
QUOTE_ID(rb_frame_callee()));

0 commit comments

Comments
 (0)