Skip to content

Preserve column when translating typespecs #13101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/elixir/lib/code/typespec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -420,5 +420,13 @@ defmodule Code.Typespec do
:error
end

defp meta(anno), do: [line: :erl_anno.line(anno)]
defp meta(anno) do
case :erl_anno.location(anno) do
{line, column} ->
[line: line, column: column]

line when is_integer(line) ->
[line: line]
end
end
end
20 changes: 13 additions & 7 deletions lib/elixir/test/elixir/typespec_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,23 +1582,29 @@ defmodule TypespecTest do
""")

[type: type] = types(:typespec_test_mod)
line = 5

assert Code.Typespec.type_to_quoted(type) ==
{:"::", [], [{:t, [], [{:x, [line: line], nil}]}, [{:x, [line: line], nil}]]}
{:"::", [],
[
{:t, [], [{:x, meta(5, 9), nil}]},
[{:x, meta(5, 20), nil}]
]}

[{{:f, 1}, [spec]}] = specs(:typespec_test_mod)
line = 7

assert Code.Typespec.spec_to_quoted(:f, spec) ==
{:when, [line: line],
{:when, meta(7, 8),
[
{:"::", [line: line],
[{:f, [line: line], [{:x, [line: line], nil}]}, {:x, [line: line], nil}]},
[x: {:var, [line: line], nil}]
{:"::", meta(7, 8),
[{:f, meta(7, 8), [{:x, meta(7, 9), nil}]}, {:x, meta(7, 15), nil}]},
[x: {:var, meta(7, 8), nil}]
]}
end

defp meta(line, column) do
[line: line, column: column]
end

defp erlc(context, module, code) do
dir = context.tmp_dir

Expand Down