Skip to content

Commit d4d7c8b

Browse files
committed
Raise when macros are given to dialyzer, closes #12597
1 parent 650c907 commit d4d7c8b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/elixir/src/elixir_module.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ validate_on_load_attribute(false, _Defs, Private, _Line, _E) -> Private.
264264
validate_dialyzer_attribute({dialyzer, Dialyzer}, Defs, Line, E) ->
265265
[case lists:keyfind(Fun, 1, Defs) of
266266
false ->
267-
elixir_errors:module_error([{line, Line}], E, ?MODULE, {bad_dialyzer, Key, Fun});
267+
elixir_errors:module_error([{line, Line}], E, ?MODULE, {bad_dialyzer_no_def, Key, Fun});
268+
{Fun, Type, _Meta, _Clauses} when Type == defmacro; Type == defmacrop ->
269+
elixir_errors:module_error([{line, Line}], E, ?MODULE, {bad_dialyzer_no_macro, Key, Fun});
268270
_ ->
269271
ok
270272
end || {Key, Funs} <- lists:flatten([Dialyzer]), Fun <- lists:flatten([Funs])];
@@ -581,8 +583,10 @@ format_error({module_in_definition, Module, File, Line}) ->
581583
[elixir_aliases:inspect(Module), elixir_utils:relative_to_cwd(File), Line]);
582584
format_error({bad_inline, {Name, Arity}}) ->
583585
io_lib:format("inlined function ~ts/~B undefined", [Name, Arity]);
584-
format_error({bad_dialyzer, Key, {Name, Arity}}) ->
586+
format_error({bad_dialyzer_no_def, Key, {Name, Arity}}) ->
585587
io_lib:format("undefined function ~ts/~B given to @dialyzer :~ts", [Name, Arity, Key]);
588+
format_error({bad_dialyzer_no_macro, Key, {Name, Arity}}) ->
589+
io_lib:format("macro ~ts/~B given to @dialyzer :~ts (@dialyzer only supports function annotations)", [Name, Arity, Key]);
586590
format_error({undefined_on_load, {Name, Arity}}) ->
587591
io_lib:format("undefined function ~ts/~B given to @on_load", [Name, Arity]);
588592
format_error({wrong_kind_on_load, {Name, Arity}, WrongKind}) ->

lib/elixir/test/elixir/kernel/errors_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,11 @@ defmodule Kernel.ErrorsTest do
769769
~c"defmodule Test do @dialyzer {:nowarn_function, {:foo, 1}} end"
770770
)
771771

772+
assert_compile_error(
773+
["nofile:1", "macro foo/1 given to @dialyzer :nowarn_function"],
774+
~c"defmodule Test do @dialyzer {:nowarn_function, {:foo, 1}}; defmacro foo(_), do: :ok end"
775+
)
776+
772777
assert_compile_error(
773778
["nofile:1", "undefined function foo/1 given to @dialyzer :no_opaque"],
774779
~c"defmodule Test do @dialyzer {:no_opaque, {:foo, 1}} end"

0 commit comments

Comments
 (0)