Skip to content

Commit fcacbfa

Browse files
committed
Use Macro.Env to record attribute warnings
Closes #13162. Closes #13164.
1 parent 7095b2c commit fcacbfa

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

lib/elixir/lib/module.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,7 @@ defmodule Module do
21352135
end
21362136

21372137
defp attribute_stack(module, line) do
2138-
file = String.to_charlist(Path.relative_to_cwd(:elixir_module.file(module)))
2139-
[{module, :__MODULE__, 0, file: file, line: line}]
2138+
struct!(Macro.Env, module: module, file: :elixir_module.file(module), line: line)
21402139
end
21412140

21422141
## Helpers

lib/elixir/test/elixir/kernel/warning_test.exs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,22 +1640,39 @@ defmodule Kernel.WarningTest do
16401640
end
16411641

16421642
test "reserved doc metadata keys" do
1643-
output =
1644-
capture_eval("""
1645-
defmodule Sample do
1646-
@typedoc opaque: false
1647-
@type t :: binary
1643+
{output, diagnostics} =
1644+
Code.with_diagnostics([log: true], fn ->
1645+
capture_eval("""
1646+
defmodule Sample do
1647+
@typedoc opaque: false
1648+
@type t :: binary
16481649
1649-
@doc defaults: 3, since: "1.2.3"
1650-
def foo(a), do: a
1651-
end
1652-
""")
1650+
@doc defaults: 3, since: "1.2.3"
1651+
def foo(a), do: a
1652+
end
1653+
""")
1654+
end)
16531655

16541656
assert output =~ "ignoring reserved documentation metadata key: :opaque"
16551657
assert output =~ "nofile:2: "
16561658
assert output =~ "ignoring reserved documentation metadata key: :defaults"
16571659
assert output =~ "nofile:5: "
16581660
refute output =~ ":since"
1661+
1662+
assert [
1663+
%{
1664+
message: "ignoring reserved documentation metadata key: :opaque",
1665+
position: 2,
1666+
file: "nofile",
1667+
severity: :warning
1668+
},
1669+
%{
1670+
message: "ignoring reserved documentation metadata key: :defaults",
1671+
position: 5,
1672+
file: "nofile",
1673+
severity: :warning
1674+
}
1675+
] = diagnostics
16591676
after
16601677
purge(Sample)
16611678
end

0 commit comments

Comments
 (0)