Skip to content

Commit

Permalink
Use Macro.Env to record attribute warnings
Browse files Browse the repository at this point in the history
Closes #13162.
Closes #13164.
  • Loading branch information
josevalim committed Dec 11, 2023
1 parent 7095b2c commit fcacbfa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
3 changes: 1 addition & 2 deletions lib/elixir/lib/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2135,8 +2135,7 @@ defmodule Module do
end

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

## Helpers
Expand Down
35 changes: 26 additions & 9 deletions lib/elixir/test/elixir/kernel/warning_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,22 +1640,39 @@ defmodule Kernel.WarningTest do
end

test "reserved doc metadata keys" do
output =
capture_eval("""
defmodule Sample do
@typedoc opaque: false
@type t :: binary
{output, diagnostics} =
Code.with_diagnostics([log: true], fn ->
capture_eval("""
defmodule Sample do
@typedoc opaque: false
@type t :: binary
@doc defaults: 3, since: "1.2.3"
def foo(a), do: a
end
""")
@doc defaults: 3, since: "1.2.3"
def foo(a), do: a
end
""")
end)

assert output =~ "ignoring reserved documentation metadata key: :opaque"
assert output =~ "nofile:2: "
assert output =~ "ignoring reserved documentation metadata key: :defaults"
assert output =~ "nofile:5: "
refute output =~ ":since"

assert [
%{
message: "ignoring reserved documentation metadata key: :opaque",
position: 2,
file: "nofile",
severity: :warning
},
%{
message: "ignoring reserved documentation metadata key: :defaults",
position: 5,
file: "nofile",
severity: :warning
}
] = diagnostics
after
purge(Sample)
end
Expand Down

0 comments on commit fcacbfa

Please sign in to comment.