From 6a8d0097095d975fbd19cf62c83645b51886025b Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 26 Feb 2012 02:26:49 +0000 Subject: [PATCH] * compile.c (iseq_compile_each): call on special object instead of self. since stabby lambda is a syntax, so it should not be affected by the context. [ruby-core:42349][Bug #5966] * insns.def (send): no special deal for FCALL. self should be put on TOS instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ compile.c | 4 ++-- insns.def | 2 +- test/ruby/test_lambda.rb | 7 +++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb17b14072..2f022be490 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sun Feb 26 11:26:44 2012 Nobuyoshi Nakada + + * compile.c (iseq_compile_each): call on special object instead of + self. since stabby lambda is a syntax, so it should not be + affected by the context. [ruby-core:42349][Bug #5966] + + * insns.def (send): no special deal for FCALL. self should be put + on TOS instead. + Sun Feb 26 05:35:43 2012 NARUSE, Yui * error.c (report_bug): use buf and snprintf to avoid consuming stack. diff --git a/compile.c b/compile.c index c8aced3672..d4b7d2c79b 100644 --- a/compile.c +++ b/compile.c @@ -208,7 +208,7 @@ r_value(VALUE value) ADD_SEND_R((seq), (line), (id), (argc), (VALUE)Qfalse, (VALUE)INT2FIX(0)) #define ADD_CALL_RECEIVER(seq, line) \ - ADD_INSN((seq), (line), putnil) + ADD_INSN((seq), (line), putself) #define ADD_CALL(seq, line, id, argc) \ ADD_SEND_R((seq), (line), (id), (argc), (VALUE)Qfalse, (VALUE)INT2FIX(VM_CALL_FCALL_BIT)) @@ -5098,7 +5098,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) /* compile same as lambda{...} */ VALUE block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, nd_line(node)); VALUE argc = INT2FIX(0); - ADD_CALL_RECEIVER(ret, nd_line(node)); + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); ADD_CALL_WITH_BLOCK(ret, nd_line(node), ID2SYM(idLambda), argc, block); if (poped) { diff --git a/insns.def b/insns.def index 59a98c0804..4c82df4c33 100644 --- a/insns.def +++ b/insns.def @@ -1012,7 +1012,7 @@ send ID id = op_id; /* get receiver */ - recv = (flag & VM_CALL_FCALL_BIT) ? GET_SELF() : TOPN(num); + recv = TOPN(num); klass = CLASS_OF(recv); me = vm_method_search(id, klass, ic); CALL_METHOD(num, blockptr, flag, id, me, recv); diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb index 02bb26939d..ae12c6d609 100644 --- a/test/ruby/test_lambda.rb +++ b/test/ruby/test_lambda.rb @@ -63,4 +63,11 @@ class TestLambdaParameters < Test::Unit::TestCase def foo assert_equal(nil, ->(&b){ b }.call) end + + def test_in_basic_object + bug5966 = '[ruby-core:42349]' + called = false + BasicObject.new.instance_eval {->() {called = true}.()} + assert_equal(true, called, bug5966) + end end