Test Broken by move to 1.14, I can't find the specific change that causes this

This test:

defmodule ThrowawayTest do
  use ExUnit.Case

  {:module, _name, bytecode, _exports} =
    defmodule TestModule do
      @type my_type() :: :a | :b | :c | :d
      def hello, do: 1
    end

  @bytecode bytecode

  test "generates the expected types" do
    assert {:ok, [type: {:my_type, _, []}]} = Code.Typespec.fetch_types(@bytecode)
  end
end

works in 1.13.4-otp-25
but is broken in 1.14.0-otp-25

It appears that nested module are no longer written to disk.

Is this a known change in the 1.14 release or a side effect?

1 Like

What error do you get?

1 Like

Code.Typespec.fetch_types(@bytecode) returns :error

I suspect that the inner module is no longer written to disk.

Just shooting in the dark: does this post help?

I have a fix for the problem (move to a real .ex module and using Code.compile_file/2, it’s more that I can’t trace the source of the problem to the 1.14 release notes.

This is a minimal reconstruction of the issue, not the full test file that I am working with.

This is strange, because @bytecode is an actual bytecode of a module. In this form, module doesn’t have to be persisted

Yet the test still fails.

Its easy to test with an asdf setup.

$ elixir x.ex
{:ok,
 [
   type: {:my_type,
    {:type, 5, :union,
     [{:atom, 0, :a}, {:atom, 0, :b}, {:atom, 0, :c}, {:atom, 0, :d}]}, []}
 ]}
$ cat x.ex
defmodule ThrowawayTest do

  {:module, _name, bytecode, _exports} =
    defmodule TestModule do
      @type my_type() :: :a | :b | :c | :d
      def hello, do: 1
    end

  @bytecode bytecode

  def test do
    Code.Typespec.fetch_types(@bytecode)
  end

end

IO.inspect ThrowawayTest.test
$ elixir --version
Erlang/OTP 24 [erts-12.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.14.0 (compiled with Erlang/OTP 24)

For me it works correctly.

And in ExUnit test this works correctly too

$ mix test
Compiling 1 file (.ex)
Generated xxx app
.

Finished in 0.03 seconds (0.00s async, 0.03s sync)
1 test, 0 failures

Randomized with seed 488666
$ cat test/xxx_test.exs
defmodule ThrowawayTest do
  use ExUnit.Case

  {:module, _name, bytecode, _exports} =
    defmodule TestModule do
      @type my_type() :: :a | :b | :c | :d
      def hello, do: 1
    end

  @bytecode bytecode

  test "generates the expected types" do
    assert {:ok, [type: {:my_type, _, []}]} = Code.Typespec.fetch_types(@bytecode)
  end
end

This is in an .exs file

Yeah, .exs works correctly too.
I’ve shown it here: Test Broken by move to 1.14, I can't find the specific change that causes this - #9 by hissssst

I am using otp 25

This works correctly on both OTP 25 and OTP 24 for me

FWIW Code.Typespec is a private module (@moduledoc false) so there’s no backwards compatibility guarantee.

2 Likes