Skip to content
Permalink
Browse files

fix for augmented subscript assignment with no values

  • Loading branch information
Alex Gaynor
Alex Gaynor committed Apr 2, 2013
1 parent f6b09d8 commit 08c3af69d7107baeb17e55f25581dc99e30ace46
Showing with 7 additions and 1 deletion.
  1. +5 −0 tests/test_parser.py
  2. +2 −1 topaz/parser.py
@@ -835,6 +835,11 @@ def test_subscript_assginment(self, space):
ast.Statement(ast.Assignment(ast.Subscript(ast.Send(ast.Self(1), "x", [], None, 1), [], 1), ast.ConstantInt(5)))
]))

def test_subscript_augmented_assignment(self, space):
assert space.parse("x[] += 5") == ast.Main(ast.Block([
ast.Statement(ast.AugmentedAssignment("+", ast.Subscript(ast.Send(ast.Self(1), "x", [], None, 1), [], 1), ast.ConstantInt(5)))
]))

def test_def(self, space):
assert space.parse("def f() end") == ast.Main(ast.Block([
ast.Statement(ast.Function(None, "f", [], None, None, ast.Nil()))
@@ -1182,9 +1182,10 @@ def arg_var_lhs_op_asgn_arg_rescue_mod(self, p):

@pg.production("arg : primary_value LITERAL_LBRACKET opt_call_args rbracket OP_ASGN arg")
def arg_subscript_op_asgn_arg(self, p):
args = p[2].getcallargs() if p[2] is not None else []
return self.new_augmented_assignment(
p[4],
BoxAST(ast.Subscript(p[0].getast(), p[2].getcallargs(), p[1].getsourcepos().lineno)),
BoxAST(ast.Subscript(p[0].getast(), args, p[1].getsourcepos().lineno)),
p[5],
)

0 comments on commit 08c3af6

Please sign in to comment.