Dialyzer "Could not get Core Erlang code for"

Here’s a repo with an example GitHub - brandynbennett/dialyzer_polyn_issue

I’ve made a library called “polyn” and am trying to include it an my app. However my app uses dialyzer and won’t pass anymore and I can’t figure it out. I’ve done mix deps.clean --all && mix deps.get && mix deps.compile I’ve done mix dialyzer.clean . None of that seems to help. Same thing happens on a brand new project. Something about the library seems to be off. The error dialyzer gives me when I run mix dialyzer.build is

dialyzer.run error: Analysis failed with error:
Could not scan the following file(s):
  Could not get Core Erlang code for: dialyzer_polyn_issue/_build/dev/lib/polyn/ebin/Elixir.Polyn.Tracing.beam
dialyzer_polyn_issue/_build/dev/lib/polyn/ebin/Elixir.Polyn.beam
...every module in the library

When I look inside _build/dev/lib/polyn/ebin/ I see all the *.beam files so I don’t understand why it can’t get them. Using versions:

erlang 25.1
elixir 1.14.0-otp-25

I could not reproduce it in that repo; I’m using ASDF with following .tool-versions:

erlang 25.2.2
elixir 1.15.0-otp-25

This thread suggests it can be issue with how Elixir was built: Dialyzer in ElixirLS cannot access .beam files for core erlang code - #5 by heathen

You saw no errors when running mix dialyzer?

The .tool-versions I had in the repo were

erlang 25.1
elixir 1.14.0-otp-25

Could there be something about those versions that causes it?

I saw the note in the thread about asdf having a problem with temporary files when compiling from source. I uninstalled erlang 25.1 and elixir 1.14.0-otp-25. I upgraded asdf brew upgrade asdf. Then I reinstalled erlang and elixir versions. Still having same issue.

I tried using newer versions

erlang 25.3.2.2
elixir 1.14.5-otp-25

and am still hitting the same issue.

When I run mix dialyzer from within the Polyn library itself I get unexpected results as well

lib/mix/tasks/polyn.gen.migration.ex:21:unknown_function
Function Mix.raise/1 does not exist.
lib/testing/testing.ex:23:unknown_function
Function ExUnit.Callbacks.start_supervised!/1 does not exist.

It doesn’t recognize any Mix module or functions as existing. I’ve tried this on both 1.14.0-otp-25 and 1.14.5-otp-25 with the same results. I don’t know if this is related to the issues in the consuming application, but thought I would surface it in case it is relevant.

Sorry, I lied. I see tons of errors, just not during analysis, but yes if I glance up a bit yes I see those same errors building the PLT. Not sure what’s going on here. I was also able to reproduce in a non-ASDF build using
this image hexpm/elixir:1.14.3-erlang-25.2.2-ubuntu-jammy-20221130

1 Like

Random shot in the dark: file permissions maybe?

All the permissions on the polyn/ebin/*.beam files are -rw-r--r--. When I check the permissions on other files for other libraries (e.g. jason, decimal, etc.) they are the same, but dialyzer doesn’t complain about them.

So diving into Dialyzer source code for the error message

Dialyzer effectively runs this:

:beam_lib.chunks(File.read!("dialyzer_polyn_issue/_build/dev/lib/polyn/ebin/Elixir.Polyn.beam"), [:debug_info])

Which results in

{:ok, {Polyn, [debug_info: {:debug_info_v1, :elixir_erl, :none}]}}

It then runs

Backend:debug_info(core_v1, Module, Metadata, Opts ++ src_compiler_opts())

Which I translate in iex to

:elixir_erl.debug_info(:core_v1, Polyn, :none, :dialyzer_utils.src_compiler_opts())

This returns me {:error, :unknown_format}

The :elixir_erl.debug_info function expects some metatdata like this {elixir_v1, Map, Specs} and the initial :beam_lib.chunks function is returning :none for the metadata.

So for some reason the Polyn beam files don’t have metadata.

When a dependency is installed by mix, Mix.env is normally :prod - you can change that with the env option

That causes polyn’s mix.exs to omit the metadata (line 14):

Yes! That fixed it. Thank you!