"Module override" warning when a file contains 2 modules

Trying to find out why the code below generates a 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, [])

Exit

iex(14)> c("te.ex")
 te.ex:1: redefining module A
 te.ex:7: redefining module B
 Inside A
 [B, A]
+4
source share
1 answer

This is not related to the call spawn. :) Each time you compile a file, the modules are redefined after the first time, since the previous version already exists. In this case, there is nothing wrong, there is a warning for cases when you accidentally redefine a module that you did not expect.

+15
source

Source: https://habr.com/ru/post/1524003/


All Articles