Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning "Redefining module" when file is containing 2 Modules

Tags:

elixir

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]
like image 896
Jack Daniel's Avatar asked Dec 04 '22 07:12

Jack Daniel's


1 Answers

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.

like image 130
José Valim Avatar answered Jun 05 '23 19:06

José Valim