Skip to content

Commit 6109768

Browse files
author
José Valim
committed
Ensure we do not ditch modules with anonymous functions in them
1 parent fbb5328 commit 6109768

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/elixir/src/elixir_compiler.erl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,21 @@ eval_forms(Forms, Line, Vars, S) ->
5959

6060
%% Pass { native, false } to speed up bootstrap
6161
%% process when native is set to true
62-
{ module(Form, S#elixir_scope.file, [{native,false}], true, fun(_, _) ->
62+
{ module(Form, S#elixir_scope.file, [{native,false}], true, fun(_, Binary) ->
6363
Res = Module:Fun(S#elixir_scope.module, Args),
6464
code:delete(Module),
65-
case code:soft_purge(Module) of
66-
true -> return_module_name(I);
67-
false -> ok
65+
66+
%% If we have labeled locals, anonymous functions
67+
%% were created and therefore we cannot ditch the
68+
%% module
69+
case beam_lib:chunks(Binary, [labeled_locals]) of
70+
{ ok, { _, [{ labeled_locals, []}] } } ->
71+
code:purge(Module),
72+
return_module_name(I);
73+
_ ->
74+
ok
6875
end,
76+
6977
Res
7078
end), FS }.
7179

@@ -162,7 +170,7 @@ core_main() ->
162170
"lib/elixir/lib/kernel.ex",
163171
"lib/elixir/lib/keyword.ex",
164172
"lib/elixir/lib/list.ex",
165-
"lib/elixir/lib/kernel/typespec.ex",
173+
"lib/elixir/lib/kernel/typespec.ex",
166174
"lib/elixir/lib/module.ex",
167175
"lib/elixir/lib/record.ex",
168176
"lib/elixir/lib/record/extractor.ex",

0 commit comments

Comments
 (0)