mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fix self value in a block is changed with return value for Fixnum, nil, instance variable.
Fix #1504
This commit is contained in:
+4
-6
@@ -278,8 +278,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
|
||||
s->iseq[s->pc-1] = MKOP_AB(OP_RETURN, GETARG_B(i0), OP_R_NORMAL);
|
||||
return;
|
||||
case OP_LOADI:
|
||||
s->iseq[s->pc-1] = MKOP_AsBx(OP_LOADI, 0, GETARG_sBx(i0));
|
||||
genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
|
||||
genop(s, MKOP_AB(OP_RETURN, GETARG_A(i0), OP_R_NORMAL));
|
||||
return;
|
||||
case OP_ARRAY:
|
||||
case OP_HASH:
|
||||
@@ -307,8 +306,8 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
|
||||
case OP_GETSPECIAL:
|
||||
case OP_LOADL:
|
||||
case OP_STRING:
|
||||
s->iseq[s->pc-1] = MKOP_ABx(c0, 0, GETARG_Bx(i0));
|
||||
genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
|
||||
s->iseq[s->pc-1] = MKOP_ABx(c0, GETARG_A(i0), GETARG_Bx(i0));
|
||||
genop(s, MKOP_AB(OP_RETURN, GETARG_A(i0), OP_R_NORMAL));
|
||||
return;
|
||||
case OP_SCLASS:
|
||||
s->iseq[s->pc-1] = MKOP_AB(c0, GETARG_A(i), GETARG_B(i0));
|
||||
@@ -319,8 +318,7 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
|
||||
case OP_LOADT:
|
||||
case OP_LOADF:
|
||||
case OP_OCLASS:
|
||||
s->iseq[s->pc-1] = MKOP_A(c0, 0);
|
||||
genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
|
||||
genop(s, MKOP_AB(OP_RETURN, GETARG_A(i0), OP_R_NORMAL));
|
||||
return;
|
||||
#if 0
|
||||
case OP_SEND:
|
||||
|
||||
+23
-2
@@ -60,13 +60,34 @@ assert('Proc#return_does_not_break_self') do
|
||||
attr_accessor :block
|
||||
def initialize
|
||||
end
|
||||
def register_block
|
||||
def return_array
|
||||
@block = Proc.new { self }
|
||||
return []
|
||||
end
|
||||
def return_instance_variable
|
||||
@block = Proc.new { self }
|
||||
return @block
|
||||
end
|
||||
def return_const_fixnum
|
||||
@block = Proc.new { self }
|
||||
return 123
|
||||
end
|
||||
def return_nil
|
||||
@block = Proc.new { self }
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
c = TestClass.new
|
||||
assert_equal [], c.register_block
|
||||
assert_equal [], c.return_array
|
||||
assert_equal c, c.block.call
|
||||
|
||||
c.return_instance_variable
|
||||
assert_equal c, c.block.call
|
||||
|
||||
assert_equal 123, c.return_const_fixnum
|
||||
assert_equal c, c.block.call
|
||||
|
||||
assert_equal nil, c.return_nil
|
||||
assert_equal c, c.block.call
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user