File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,12 @@ defmodule Mix.Tasks.Compile.Erlang do
80
80
81
81
Mix.Compilers.Erlang . compile ( manifest ( ) , tuples , fn
82
82
input , _output ->
83
+ # We're purging the module because a previous compiler (e.g. Phoenix)
84
+ # might have already loaded the previous version of it.
85
+ module = Path . basename ( input , ".erl" ) |> String . to_atom
86
+ :code . purge ( module )
87
+ :code . delete ( module )
88
+
83
89
file = to_erl_file ( Path . rootname ( input , ".erl" ) )
84
90
:compile . file ( file , erlc_options )
85
91
end )
Original file line number Diff line number Diff line change @@ -59,4 +59,25 @@ defmodule Mix.Tasks.Compile.ErlangTest do
59
59
refute File . regular? ( "_build/dev/lib/sample/ebin/b.beam" )
60
60
end
61
61
end
62
+
63
+ test "compilation purges the module" do
64
+ in_fixture "compile_erlang" , fn ->
65
+ # Create the first version of the module.
66
+ defmodule :purge_test do
67
+ def version , do: :v1
68
+ end
69
+ assert :v1 == :purge_test . version
70
+
71
+ # Create the second version of the module (this time as Erlang source).
72
+ File . write! "src/purge_test.erl" , """
73
+ -module(purge_test).
74
+ -compile(export_all).
75
+ version() -> v2.
76
+ """
77
+ assert Mix.Tasks.Compile.Erlang . run ( [ ] ) == :ok
78
+
79
+ # If the module was not purged on recompilation, this would fail.
80
+ assert :v2 == :purge_test . version
81
+ end
82
+ end
62
83
end
You can’t perform that action at this time.
0 commit comments