It is not related to the spawn
call. :) Every time you compile the file, after the first time, the modules are being redefined because a previous version already existed. There is nothing wrong in this case, the warning is there for the cases you accidentally redefine a module you did not expect to.
Warning "Redefining module" when file is containing 2 Modules
-
03-10-2022 - |
Question
Trying to figure out why below code is generating warning
defmodule A do
def greet do
IO.puts "Inside A"
end
end
defmodule B do
def greet do
IO.puts "Inside B"
end
end
spawn(A, :greet, [])
Output
iex(14)> c("te.ex")
te.ex:1: redefining module A
te.ex:7: redefining module B
Inside A
[B, A]
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow