Skip to content

Commit

Permalink
Add operator info to OP_ASGN2 of RubyVM::AbstractSyntaxTree.
Browse files Browse the repository at this point in the history
  • Loading branch information
osyo-manga authored and nobu committed Jul 5, 2020
1 parent 988b4bc commit 8e189df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,10 @@ node_children(rb_ast_t *ast, NODE *node)
NEW_CHILD(ast, node->nd_args->nd_head),
NEW_CHILD(ast, node->nd_args->nd_body));
case NODE_OP_ASGN2:
return rb_ary_new_from_args(4, NEW_CHILD(ast, node->nd_recv),
return rb_ary_new_from_args(5, NEW_CHILD(ast, node->nd_recv),
node->nd_next->nd_aid ? Qtrue : Qfalse,
ID2SYM(node->nd_next->nd_vid),
ID2SYM(node->nd_next->nd_mid),
NEW_CHILD(ast, node->nd_value));
case NODE_OP_ASGN_AND:
return rb_ary_new_from_args(3, NEW_CHILD(ast, node->nd_head), ID2SYM(idANDOP),
Expand Down
11 changes: 11 additions & 0 deletions test/ruby/test_ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,15 @@ def test_ranges_numbered_parameter
helper.validate_range
assert_equal([], helper.errors)
end

def test_op_asgn2
node = RubyVM::AbstractSyntaxTree.parse("struct.field += foo")
_, _, body = *node.children
assert_equal(:OP_ASGN2, body.type)
recv, _, mid, op, value = body.children
assert_equal(:VCALL, recv.type)
assert_equal(:field, mid)
assert_equal(:+, op)
assert_equal(:VCALL, value.type)
end
end

0 comments on commit 8e189df

Please sign in to comment.