Skip to content

Commit 9a86e35

Browse files
committed
[Bug #21985] Include the - in the negative numbers location
1 parent aa2b4ab commit 9a86e35

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

parse.y

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ static NODE *new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw
14421442
static rb_node_kw_arg_t *new_kw_arg(struct parser_params *p, NODE *k, const YYLTYPE *loc);
14431443
static rb_node_args_t *args_with_numbered(struct parser_params*,rb_node_args_t*,int,ID);
14441444

1445-
static NODE* negate_lit(struct parser_params*, NODE*);
1445+
static NODE* negate_lit(struct parser_params*, NODE*,const YYLTYPE*);
14461446
static void no_blockarg(struct parser_params*,NODE*);
14471447
static NODE *ret_args(struct parser_params*,NODE*);
14481448
static NODE *arg_blk_pass(NODE*,rb_node_block_pass_t*);
@@ -6133,7 +6133,7 @@ numeric : simple_numeric
61336133
| tUMINUS_NUM simple_numeric %prec tLOWEST
61346134
{
61356135
$$ = $2;
6136-
negate_lit(p, $$);
6136+
negate_lit(p, $$, &@$);
61376137
/*% ripper: unary!(ID2VAL(idUMinus), $:2) %*/
61386138
}
61396139
;
@@ -14358,7 +14358,7 @@ ret_args(struct parser_params *p, NODE *node)
1435814358
}
1435914359

1436014360
static NODE*
14361-
negate_lit(struct parser_params *p, NODE* node)
14361+
negate_lit(struct parser_params *p, NODE* node, const YYLTYPE *loc)
1436214362
{
1436314363
switch (nd_type(node)) {
1436414364
case NODE_INTEGER:
@@ -14374,6 +14374,7 @@ negate_lit(struct parser_params *p, NODE* node)
1437414374
RNODE_IMAGINARY(node)->minus = TRUE;
1437514375
break;
1437614376
}
14377+
node->nd_loc = *loc;
1437714378
return node;
1437814379
}
1437914380

test/ruby/test_ast.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,11 @@ def test_yield_locations
17461746
assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 9, 1, 20], [1, 9, 1, 14], [1, 14, 1, 15], [1, 19, 1, 20]])
17471747
end
17481748

1749+
def test_negative_numeric_locations
1750+
node = ast_parse("-1")
1751+
assert_locations(node.children.last.locations, [[1, 0, 1, 2]])
1752+
end
1753+
17491754
private
17501755
def ast_parse(src, **options)
17511756
begin

0 commit comments

Comments
 (0)