Skip to content

Commit 4644e4f

Browse files
committed
[Bug #21986] Fix location of numeric literal
When checking for suffixes, do not flush the numeric literal token even if no suffix is found.
1 parent f4b5566 commit 4644e4f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

parse.y

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8927,7 +8927,6 @@ number_literal_suffix(struct parser_params *p, int mask)
89278927
}
89288928
if (!ISASCII(c) || ISALPHA(c) || c == '_') {
89298929
p->lex.pcur = lastp;
8930-
literal_flush(p, p->lex.pcur);
89318930
return 0;
89328931
}
89338932
pushback(p, c);

test/ruby/test_ast.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,14 @@ def test_negative_numeric_locations
17511751
assert_locations(node.children.last.locations, [[1, 0, 1, 2]])
17521752
end
17531753

1754+
def test_numeric_location_with_nonsuffix
1755+
node = ast_parse("1if true")
1756+
assert_locations(node.children.last.children[1].locations, [[1, 0, 1, 1]])
1757+
1758+
node = ast_parse("1q", error_tolerant: true)
1759+
assert_locations(node.children.last.locations, [[1, 0, 1, 1]])
1760+
end
1761+
17541762
private
17551763
def ast_parse(src, **options)
17561764
begin

0 commit comments

Comments
 (0)