Skip to content

Commit b18cdb0

Browse files
committed
Do not persist temporary compilation warnings, closes #14768
1 parent 62949b0 commit b18cdb0

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

lib/elixir/lib/module.ex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,20 @@ defmodule Module do
560560
callback is invoked under different scenarios, Elixir provides no guarantees
561561
of when in the compilation cycle nor in which process the callback runs.
562562
563+
Furthermore, after verification callbacks are not expected to raise.
564+
Given they run after the code is compiled, artifacts have already been
565+
written to disk, and therefore raising does not effectively halt compilation
566+
and may leave unused artifacts on disk. If you must raise, use `@after_compile`
567+
or other callback. Given modules have already been compiled, functions in
568+
ths module, such as `get_attribute/2`, which expect modules to not have been
569+
yet compiled, do not work on `@after_verify` callback.
570+
563571
Accepts a module or a `{module, function_name}` tuple. The function
564572
must take one argument: the module name. When just a module is provided,
565573
the function is assumed to be `__after_verify__/1`.
566574
567575
Callbacks will run in the order they are registered.
568576
569-
`Module` functions expecting not yet compiled modules are no longer available
570-
at the time `@after_verify` is invoked.
571-
572577
#### Example
573578
574579
defmodule MyModule do

lib/elixir/src/elixir_errors.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ emit_diagnostic(Severity, Position, File, Message, Stacktrace, Options) ->
109109

110110
case get(elixir_code_diagnostics) of
111111
undefined ->
112+
StoreDiagnostic = proplists:get_value(store_diagnostic, Options, true),
113+
112114
case get(elixir_compiler_info) of
113-
undefined -> print_diagnostic(Diagnostic, ReadSnippet);
114-
{CompilerPid, _} -> CompilerPid ! {diagnostic, Diagnostic, ReadSnippet}
115+
{CompilerPid, _} when StoreDiagnostic -> CompilerPid ! {diagnostic, Diagnostic, ReadSnippet};
116+
_ -> print_diagnostic(Diagnostic, ReadSnippet)
115117
end;
116118

117119
{Tail, true} ->

lib/elixir/src/elixir_module.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ check_module_availability(Module, Line, E) ->
375375
false ->
376376
case code:ensure_loaded(Module) of
377377
{module, _} ->
378-
elixir_errors:file_warn([{line, Line}], E, ?MODULE, {module_defined, Module});
378+
%% This diagnostic is by definition temporary
379+
WarnMeta = [{store_diagnostic, false}, {line, Line}],
380+
elixir_errors:file_warn(WarnMeta, E, ?MODULE, {module_defined, Module});
379381
{error, _} ->
380382
ok
381383
end;

lib/mix/test/mix/tasks/compile.elixir_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -933,13 +933,13 @@ defmodule Mix.Tasks.Compile.ElixirTest do
933933
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
934934
purge([A, B])
935935

936-
capture_io(:stderr, fn ->
937-
File.write!("lib/a.ex", "defmodule B, do: :not_ok")
938-
assert {:ok, [_ | _]} = Mix.Tasks.Compile.Elixir.run(["--verbose"])
939-
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
940-
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
941-
purge([A, B])
942-
end)
936+
assert capture_io(:stderr, fn ->
937+
File.write!("lib/a.ex", "defmodule B, do: :not_ok")
938+
assert {:ok, []} = Mix.Tasks.Compile.Elixir.run(["--verbose"])
939+
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
940+
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
941+
purge([A, B])
942+
end) =~ "redefining module B"
943943

944944
capture_io(:stderr, fn ->
945945
File.write!("lib/a.ex", "defmodule A, do: :ok")

0 commit comments

Comments
 (0)