Meck compilation failures with OTP 20.0

I use mock 0.2.1 in my ExUnit test suite. Tests pass with Elixir 1.4 (1.4.4 and 1.4.5) and OTP 18.3, 19.3 and 20.0-rc1, but I get errors with OTP 20.0. The errors happen in some, but not all, tests that create mocks.

The error is always the same but the stacktrace is not always present:

     ** (ErlangError) erlang error: {:compile_forms, {:error, [{[], [{:none, :compile, {:crash, :lint_module, {:badarg, [{:erlang, :atom_to_list, [[GenServer]], []}, {:erl_lint, :is_latin1_name, 1, [file: 'erl_lint.erl', line: 3055]}, {:erl_lint, :check_module_name, 3, [file: 'erl_lint.erl', line: 3048]}, {:erl_lint, :behaviour_callbacks, 3, [file: 'erl_lint.erl', line: 973]}, {:erl_lint, :all_behaviour_callbacks, 3, [file: 'erl_lint.erl', line: 934]}, {:erl_lint, :behaviour_check, 2, [file: 'erl_lint.erl', line: 921]}, {:erl_lint, :post_traversal_check, 2, [file: 'erl_lint.erl', line: 893]}, {:erl_lint, :module, 3, [file: 'erl_lint.erl', line: 536]}, {:compile, :lint_module, 2, [file: 'compile.erl', line: 1109]}, {:compile, :"-internal_comp/5-anonymous-1-", 3, [file: 'compile.erl', line: 342]}, {:compile, :fold_comp, 4, [file: 'compile.erl', line: 369]}, {:compile, :internal_comp, 5, [file: 'compile.erl', line: 353]}, {:compile, :"-do_compile/2-anonymous-0-", 2, [file: 'compile.erl', line: 177]}, {:compile, :"-do_compile/2-anonymous-1-", 1, [file: 'compile.erl', line: 190]}]}}}]}], []}}
       (meck) src/meck_proc.erl:95: :meck_proc.start(MyMocked.ModuleFoo, [:passthrough])
       test/my_mocked/module_foo_test.exs:395: anonymous fn/2 in MyMocked.ModuleFooTest.test the test description I typed for this specific test case/1
       (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
       test/my_mocked/module_foo_test.exs:395: (test)

It looks like sometimes the mocks are not cleared and “leak” in other tests, judging from this other kind of errors that happens randomly:

     ** (UndefinedFunctionError) function Foo.Bar.baz/0 is undefined or private. Did you mean one of:

           * baz/0

You can inspect the failures on the Travis build. I’ve setup a broad test matrix to show that the problem was introduced between OTP 20.0-rc1 and the final 20.0.

I have raised an issue on the Mock project, but this looks more like an Elixir and Erlang issue. I would appreciate some guidance before opening an issue on the Elixir-lang repo.

Thank you!

It seems to be caused by an issue with meck. More details here.