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]
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top