mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: Fix a bug of obj[42, &blk] ||= foo bar
Follow up of r28123 (!) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
53c6960ddf
commit
c2052b027c
2 changed files with 30 additions and 1 deletions
5
parse.y
5
parse.y
|
@ -1298,7 +1298,12 @@ command_asgn : lhs '=' command_rhs
|
||||||
|
|
||||||
value_expr($6);
|
value_expr($6);
|
||||||
$3 = make_array($3, &@3);
|
$3 = make_array($3, &@3);
|
||||||
|
if (nd_type($3) == NODE_BLOCK_PASS) {
|
||||||
|
args = NEW_ARGSCAT($3, $6, &@$);
|
||||||
|
}
|
||||||
|
else {
|
||||||
args = arg_concat(p, $3, $6, &@$);
|
args = arg_concat(p, $3, $6, &@$);
|
||||||
|
}
|
||||||
$$ = NEW_OP_ASGN1($1, $5, args, &@$);
|
$$ = NEW_OP_ASGN1($1, $5, args, &@$);
|
||||||
fixpos($$, $1);
|
fixpos($$, $1);
|
||||||
/*%
|
/*%
|
||||||
|
|
|
@ -457,6 +457,30 @@ class TestParse < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_op_asgn1_with_block
|
||||||
|
t = Object.new
|
||||||
|
a = []
|
||||||
|
blk = proc {|x| a << x }
|
||||||
|
def t.[](_)
|
||||||
|
yield(:aref)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
def t.[]=(_, _)
|
||||||
|
yield(:aset)
|
||||||
|
end
|
||||||
|
def t.dummy(_)
|
||||||
|
end
|
||||||
|
eval <<-END, nil, __FILE__, __LINE__+1
|
||||||
|
t[42, &blk] ||= 42
|
||||||
|
END
|
||||||
|
assert_equal([:aref, :aset], a)
|
||||||
|
a.clear
|
||||||
|
eval <<-END, nil, __FILE__, __LINE__+1
|
||||||
|
t[42, &blk] ||= t.dummy 42 # command_asgn test
|
||||||
|
END
|
||||||
|
assert_equal([:aref, :aset], a)
|
||||||
|
end
|
||||||
|
|
||||||
def test_backquote
|
def test_backquote
|
||||||
t = Object.new
|
t = Object.new
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue