Elixir and Erlang/OTP versions
Erlang/OTP 27 [erts-15.2.7.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.19.0-rc.0 (2a9a4f2) (compiled with Erlang/OTP 27)
Operating system
macOS
Current behavior
With the help of @zachdaniel, who gave me the necessary context finally figure this out, we tracked it down to the @after_verify hook.
Verified that the issue exists in Elixir 1.18.4 and 1.19.0-rc.0, but @zachdaniel also tried the main branch, which seemed to not have this issue. So this might be a non-issue for 1.20+, but a fix for 1.18 and 1.19 would be great!
If the compiler exits in an @after_verify hook, all compiled modules in that context will produce the "redefining module" error on all subsequent compilations
A reproduction repository with instructions can be found at: https://github.com/simpers/redefining-reprod
In bigger projects where a change to a module affects a whole list of dependents, this will cause all of the modules affected to henceforth output this redefining module error, until mix clean is called.
Example output from reprod repo after the issue has been triggered:
$ mix compile
warning: redefining module Reprod (current version loaded from _build/dev/lib/reprod/ebin/Elixir.Reprod.beam)
│
1 │ defmodule Reprod do
│ ~~~~~~~~~~~~~~~~~~~
│
└─ lib/reprod.ex:1: Reprod (module)
warning: redefining module Reprod.Sad (current version loaded from _build/dev/lib/reprod/ebin/Elixir.Reprod.Sad.beam)
│
1 │ defmodule Reprod.Sad do
│ ~~~~~~~~~~~~~~~~~~~~~~~
│
└─ lib/reprod/sad.ex:1: Reprod.Sad (module)
Expected behavior
The warnings should not get stuck like this, and also they are false warnings.