mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* variable.c (set_const_visibility): clear inine-cache when constant's
visibility is modified. [ruby-dev:44929] * test/ruby/test_module.rb (test_private_constants_clear_inlinecache): add test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f6a2a43116
commit
1fd41dce10
3 changed files with 38 additions and 3 deletions
|
@ -1,3 +1,11 @@
|
|||
Thu Dec 8 23:38:24 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
|
||||
|
||||
* variable.c (set_const_visibility): clear inine-cache when constant's
|
||||
visibility is modified. [ruby-dev:44929]
|
||||
|
||||
* test/ruby/test_module.rb (test_private_constants_clear_inlinecache):
|
||||
add test for it.
|
||||
|
||||
Thu Dec 8 23:26:11 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* ext/extmk.rb (extract_makefile): should sort after map, not before
|
||||
|
|
|
@ -1130,6 +1130,27 @@ class TestModule < Test::Unit::TestCase
|
|||
assert_in_out_err([], src, %w(Object :ok), [])
|
||||
end
|
||||
|
||||
def test_private_constants_clear_inlinecache
|
||||
bug5702 = '[ruby-dev:44929]'
|
||||
src = <<-INPUT
|
||||
class A
|
||||
C = :Const
|
||||
def self.get_C
|
||||
A::C
|
||||
end
|
||||
# fill cache
|
||||
A.get_C
|
||||
private_constant :C, :D rescue nil
|
||||
begin
|
||||
A.get_C
|
||||
rescue NameError
|
||||
puts "A.get_C"
|
||||
end
|
||||
end
|
||||
INPUT
|
||||
assert_in_out_err([], src, %w(A.get_C), [], bug5702)
|
||||
end
|
||||
|
||||
def test_constant_lookup_in_method_defined_by_class_eval
|
||||
src = <<-INPUT
|
||||
class A
|
||||
|
|
10
variable.c
10
variable.c
|
@ -2119,14 +2119,20 @@ set_const_visibility(VALUE mod, int argc, VALUE *argv, rb_const_flag_t flag)
|
|||
VALUE val = argv[i];
|
||||
id = rb_check_id(&val);
|
||||
if (!id) {
|
||||
if ( i > 0 )
|
||||
rb_clear_cache_by_class(mod);
|
||||
rb_name_error_str(val, "constant %s::%s not defined", rb_class2name(mod), RSTRING_PTR(val));
|
||||
}
|
||||
if (RCLASS_CONST_TBL(mod) && st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
|
||||
if (RCLASS_CONST_TBL(mod) &&
|
||||
st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
|
||||
((rb_const_entry_t*)v)->flag = flag;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if ( i > 0 )
|
||||
rb_clear_cache_by_class(mod);
|
||||
rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id));
|
||||
}
|
||||
}
|
||||
rb_clear_cache_by_class(mod);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue