Skip to content

Commit

Permalink
* vm_insnhelper.c (vm_get_ev_const): should ignore crefs with
Browse files Browse the repository at this point in the history
  the NODE_FL_CREF_PUSHED_BY_EVAL flag.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
shugo committed Mar 31, 2011
1 parent 4273aa8 commit 7487298
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Thu Mar 31 18:06:12 2011 Shugo Maeda <shugo@ruby-lang.org>

* vm_insnhelper.c (vm_get_ev_const): should ignore crefs with
the NODE_FL_CREF_PUSHED_BY_EVAL flag.

Thu Mar 31 16:49:56 2011 Shugo Maeda <shugo@ruby-lang.org>

* vm_insnhelper.c (vm_get_ev_const): search root cref properly.
Expand Down
19 changes: 19 additions & 0 deletions test/ruby/test_module.rb
Expand Up @@ -1049,4 +1049,23 @@ module X
INPUT
assert_in_out_err([], src, ["uninitialized constant A"], [])
end

def test_constant_lookup_in_module_in_class_eval
src = <<-INPUT
class A
B = 42
end
A.class_eval do
module C
begin
B
rescue NameError
puts "NameError"
end
end
end
INPUT
assert_in_out_err([], src, ["NameError"], [])
end
end
7 changes: 6 additions & 1 deletion vm_insnhelper.c
Expand Up @@ -1164,7 +1164,12 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq,
}
cref = root_cref;
while (cref && cref->nd_next) {
klass = cref->nd_clss;
if (cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) {
klass = Qnil;
}
else {
klass = cref->nd_clss;
}
cref = cref->nd_next;

if (!NIL_P(klass)) {
Expand Down

0 comments on commit 7487298

Please sign in to comment.