From 09946ee77677cbac02a9ef670f88bf38f48f7eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 23 Oct 2023 20:12:18 +0200 Subject: [PATCH] Include column information on definition metadata Closes #13029. --- lib/elixir/src/elixir_def.erl | 9 +++++++-- lib/elixir/test/elixir/module_test.exs | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/elixir/src/elixir_def.erl b/lib/elixir/src/elixir_def.erl index 8d018803513..a642a643536 100644 --- a/lib/elixir/src/elixir_def.erl +++ b/lib/elixir/src/elixir_def.erl @@ -148,11 +148,16 @@ store_definition(Kind, HasNoUnquote, Call, Body, #{line := Line} = E) -> %% extract meta information like file and context. {_, Meta, _} = Call, - Context = case lists:keyfind(context, 1, Meta) of - {context, _} = ContextPair -> [ContextPair]; + Column = case lists:keyfind(column, 1, Meta) of + {column, _} = ColumnPair -> [ColumnPair]; _ -> [] end, + Context = case lists:keyfind(context, 1, Meta) of + {context, _} = ContextPair -> [ContextPair | Column]; + _ -> Column + end, + Generated = case lists:keyfind(generated, 1, Meta) of {generated, true} -> ?generated(Context); _ -> Context diff --git a/lib/elixir/test/elixir/module_test.exs b/lib/elixir/test/elixir/module_test.exs index c6a7a43b031..1c0f31e6085 100644 --- a/lib/elixir/test/elixir/module_test.exs +++ b/lib/elixir/test/elixir/module_test.exs @@ -523,12 +523,14 @@ defmodule ModuleTest do in_module do def foo(a, b), do: a + b - assert {:v1, :def, _, + assert {:v1, :def, def_meta, [ - {_, [{:a, _, nil}, {:b, _, nil}], [], + {clause_meta, [{:a, _, nil}, {:b, _, nil}], [], {{:., _, [:erlang, :+]}, _, [{:a, _, nil}, {:b, _, nil}]}} ]} = Module.get_definition(__MODULE__, {:foo, 2}) + assert [line: _, column: _] = Keyword.take(def_meta, [:line, :column]) + assert [line: _, column: _] = Keyword.take(clause_meta, [:line, :column]) assert {:v1, :def, _, []} = Module.get_definition(__MODULE__, {:foo, 2}, skip_clauses: true) assert Module.delete_definition(__MODULE__, {:foo, 2})