Skip to content

Commit f2ad982

Browse files
committed
Only consider StartColumn on first line
1 parent edcb909 commit f2ad982

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/elixir/src/elixir_errors.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ snippet(InputString, Location, StartLine, StartColumn) ->
8888
{column, Column} ->
8989
Lines = string:split(InputString, "\n", all),
9090
Snippet = elixir_utils:characters_to_binary(lists:nth(Line - StartLine + 1, Lines)),
91-
#{content => Snippet, offset => (Column - StartColumn)};
91+
Offset = if Line == StartLine -> Column - StartColumn; true -> Column - 1 end,
92+
#{content => Snippet, offset => Offset};
9293

9394
false ->
9495
nil

lib/elixir/test/elixir/code_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ defmodule CodeTest do
158158
assert_raise SyntaxError, message, fn ->
159159
Code.string_to_quoted!("1 + * 3", line: 10, column: 3)
160160
end
161+
162+
message = "nofile:11:5: syntax error before: '*'\n |\n 11 | 1 + * 3\n | ^"
163+
164+
assert_raise SyntaxError, message, fn ->
165+
Code.string_to_quoted!(":ok\n1 + * 3", line: 10, column: 3)
166+
end
161167
end
162168

163169
test "compile source" do

0 commit comments

Comments
 (0)