5

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]
Jonas
  • 121,568
  • 97
  • 310
  • 388
Jack Daniel's
  • 2,583
  • 22
  • 28

1 Answers1

18

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.

José Valim
  • 50,409
  • 12
  • 130
  • 115
  • 1
    Thanks Jose, But it's confusing... because iex doesnt tell whether its error, warning, notification or what... which may lead developer in wrong direction as if there is no output developer may think its because of redefining error.. – Jack Daniel's Jan 28 '14 at 06:39
  • 7
    Good point. I have opened an issue to make sure we prefix those with `warning:`. Thank you! – José Valim Jan 28 '14 at 11:09