ruby-changes:35563
From: nobu <ko1@a...>
Date: Sat, 20 Sep 2014 07:56:14 +0900 (JST)
Subject: [ruby-changes:35563] nobu:r47645 (trunk): vm_eval.c: fix super from eval with scope
nobu 2014-09-20 07:55:59 +0900 (Sat, 20 Sep 2014) New Revision: 47645 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47645 Log: vm_eval.c: fix super from eval with scope * vm_eval.c (eval_string_with_cref): fix super from eval with scope. set klass in the current control frame to the class of the receiver in the context to be evaluated, this class/module must match the actual receiver to call super. [ruby-core:65122] [Bug #10263] Modified files: trunk/ChangeLog trunk/test/ruby/test_super.rb trunk/vm_eval.c Index: ChangeLog =================================================================== --- ChangeLog (revision 47644) +++ ChangeLog (revision 47645) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Sep 20 07:55:57 2014 Nobuyoshi Nakada <nobu@r...> + + * vm_eval.c (eval_string_with_cref): fix super from eval with + scope. set klass in the current control frame to the class of + the receiver in the context to be evaluated, this class/module + must match the actual receiver to call super. + [ruby-core:65122] [Bug #10263] + Fri Sep 19 20:06:00 2014 Nobuyoshi Nakada <nobu@r...> * symbol.c (rb_str_dynamic_intern): check if the stem ID of Index: vm_eval.c =================================================================== --- vm_eval.c (revision 47644) +++ vm_eval.c (revision 47645) @@ -1215,7 +1215,7 @@ eval_string_with_cref(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1215 absolute_path = file; } - if (scope != Qnil) { + if (!NIL_P(scope)) { bind = Check_TypedStruct(scope, &ruby_binding_data_type); { envval = bind->env; @@ -1265,6 +1265,7 @@ eval_string_with_cref(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1265 COPY_CREF(cref, orig_cref); } vm_set_eval_stack(th, iseqval, cref, base_block); + th->cfp->klass = CLASS_OF(base_block->self); RB_GC_GUARD(crefval); if (0) { /* for debug */ Index: test/ruby/test_super.rb =================================================================== --- test/ruby/test_super.rb (revision 47644) +++ test/ruby/test_super.rb (revision 47645) @@ -493,4 +493,19 @@ class TestSuper < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_super.rb#L493 end assert_equal(%w[B A], result, bug9721) end + + def test_from_eval + bug10263 = '[ruby-core:65122] [Bug #10263a]' + a = Class.new do + def foo + "A" + end + end + b = Class.new(a) do + def foo + binding.eval("super") + end + end + assert_equal("A", b.new.foo, bug10263) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/