summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-28 17:57:42 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-28 17:57:42 +0000
commitb1e829fb30be8a1a5c842a981ed9eacf9c77b1a3 (patch)
treeafb1bf63e88cd56f765d0e6023d0b2df68c7e5e2 /variable.c
parenta2ec8666cf8fbb579fa48c73bd114908dbbc4a85 (diff)
* variable.c (rb_const_set): const_set shoud preserve constant
visibility. see [ruby-core:32912]. * test/ruby/test_module.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/variable.c b/variable.c
index 1f4cf76fae..1ee299e358 100644
--- a/variable.c
+++ b/variable.c
@@ -1876,6 +1876,7 @@ void
rb_const_set(VALUE klass, ID id, VALUE val)
{
rb_const_entry_t *ce;
+ VALUE visibility = CONST_PUBLIC;
if (NIL_P(klass)) {
rb_raise(rb_eTypeError, "no class/module to define constant %s",
@@ -1890,17 +1891,20 @@ rb_const_set(VALUE klass, ID id, VALUE val)
st_data_t value;
if (st_lookup(RCLASS_CONST_TBL(klass), (st_data_t)id, &value)) {
- if (((rb_const_entry_t*)value)->value == Qundef)
+ rb_const_entry_t *ce = (rb_const_entry_t*)value;
+ if (ce->value == Qundef)
autoload_delete(klass, id);
- else
+ else {
+ visibility = ce->flag;
rb_warn("already initialized constant %s", rb_id2name(id));
+ }
}
}
rb_vm_change_state();
ce = ALLOC(rb_const_entry_t);
- ce->flag = CONST_PUBLIC;
+ ce->flag = visibility;
ce->value = val;
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);