Skip to content

Commit debf9b4

Browse files
authored
Fix Call#end_location w/ named arguments off-by-one error (#16542)
1 parent 1345a68 commit debf9b4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spec/compiler/parser/parser_spec.cr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,6 +2653,13 @@ module Crystal
26532653
assert_end_location "[1, 2,]"
26542654
assert_end_location "foo(\n &.block\n)", line_number: 3, column_number: 1
26552655
assert_end_location "foo.bar(x) do; end"
2656+
assert_end_location "foo(bar: 123)"
2657+
assert_end_location "foo bar: 123"
2658+
assert_end_location "f foo(bar: 123)"
2659+
assert_end_location "f(foo bar: 123)"
2660+
assert_end_location "f foo bar: 123"
2661+
assert_end_location "f foo(x: 123, &.bar)"
2662+
assert_end_location "f foo x: 123, &.bar"
26562663
assert_end_location "%w(one two)"
26572664
assert_end_location "{%\nif foo\n bar\n end\n%}", line_number: 5, column_number: 2
26582665
assert_end_location "foo bar, out baz"

src/compiler/crystal/syntax/parser.cr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4851,7 +4851,12 @@ module Crystal
48514851
end
48524852

48534853
check :OP_RPAREN if allow_newline
4854-
end_location = token_end_location
4854+
4855+
# Prefer the end location of the last named argument when available.
4856+
# Using `token_end_location` would produce an off-by-one column
4857+
# in some cases (see issue #16092).
4858+
end_location = named_args.last?.try(&.end_location) unless allow_newline
4859+
end_location ||= token_end_location
48554860

48564861
if allow_newline
48574862
next_token_skip_space

0 commit comments

Comments
 (0)