Dialyzer in ElixirLS cannot access .beam files for core erlang code

For some reason dialyzer task in elixir-ls keeps crashing.

Macbook pro 13 m1 
Big Sur 11.2.2 (20D80)
VSCode      - February 2021 (version 1.54)
ElixirLS    - 0.6.5
elixir      - 1.11.3 (compiled with Erlang/OTP 23 from sources - ref:d30c5c0185607f08797441ab8af12636ad8dbd7e)
erlang      - 23.2.7
asdf        - v0.8.0-c6145d0
13:05:20.785 [error] Task #PID<0.122.0> started from #PID<0.121.0> terminating
** (stop) {:nocatch, {:dialyzer_error, 'Analysis failed with error:\nCould not scan the following file(s):\n  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/zip.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/win32reg.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/uri_string.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/unicode_util.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/unicode.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/timer.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/sys.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/supervisor_bridge.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/supervisor.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/sofs.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/string.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validates compile_env/_build/dev/rel/compile_env_config/lib/stdlib-3.13.2/ebin/slave.beam\n  Recompile with +debug_info or analyze starting from source code  Could not get Core Erlang code for: /Users/roman/.asdf/installs/elixir/ref-d30c5c0185607f08797441ab8af12636ad8dbd7e/bin/../lib/mix/tmp/Mix.Tasks.ReleaseTest/test validate' ++ ...}}
    (dialyzer 4.3) dialyzer_cl.erl:699: :dialyzer_cl.cl_error/2
    (dialyzer 4.3) dialyzer_cl.erl:401: :dialyzer_cl.do_analysis/4
    (dialyzer 4.3) dialyzer.erl:160: :dialyzer.run/1
    (language_server 0.6.5) lib/language_server/dialyzer/manifest.ex:146: ElixirLS.LanguageServer.Dialyzer.Manifest.build_elixir_plt/0
    (language_server 0.6.5) lib/language_server/dialyzer/manifest.ex:14: anonymous fn/1 in ElixirLS.LanguageServer.Dialyzer.Manifest.build_new_manifest/0
    (elixir 1.11.3) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: #Function<2.129723316/0 in ElixirLS.LanguageServer.Dialyzer.Manifest.build_new_manifest/0>
    Args: []

Deleting _build, deps, .elixir_ls directories did not help.
I tried compiling elixir with different erlang versions down to 23.0, but it did not seem to help.
If I run dialyzer manually it succeeds both in dev and test environments.
Switching to precompiled elixir 1.11.3 helps, but I lose the ability to go to the sources.

Does anyone else have this problem?

2 Likes

Yes, I have the same problem

The Erlang, was it built from sources or a prebuilt binary?

In my case both Erlang and Elixir were built from sources (Erlang 24.0-rc1, Elixir v1.11.4) with asdf

Seems that I finally got it working: it works with Erlang 24.0-rc1 (installed via asdf install but effectively built from sources), Elixir 1.11.4-OTP-23 (asdf install precompiled) and vscode-elixir-ls rebuilt from sources. I also changed elixir-ls language server dialyxir dependency from “~> 1.0.0” to “~> 1.1.0” (elixir-ls/apps/language_server/mix.exs).

Started ElixirLS v0.6.5
Elixir version: "1.11.4 (compiled with Erlang/OTP 23)"
Erlang version: "24"
ElixirLS compiled with Elixir 1.11.4 and erlang 24
 ~/P/v/elixir-ls > elixir -v                                                                                                  
Erlang/OTP 24 [RELEASE CANDIDATE 1] [erts-12.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Elixir 1.11.4 (compiled with Erlang/OTP 23)
 ~/P/v/elixir-ls >

Could you maybe elaborate on that last point for a bit? How exactly did you change the dialyxir dependency for the extension? The extension comes prebuilt for VS Code, right? Or did you compile the extension locally as well?

Yes, I’ve compiled the extension locally and then installed it to the VS Code as mentioned here. But please note that ElixirLS will not work with any projects require OTP version lower than you’ve used for elixir-ls compilation so if you compile it with OTP-24 it will give errors for OTP-23 projects (at least it does for me).

This issue seems to be related to temporary files created when building elixir from source. I’ve made a PR for asdf’s elixir plugin to fix this issue for elixir versions installed from source using asdf: Install from-sources elixir with `make DESTDIR=... install` by juulSme · Pull Request #99 · asdf-vm/asdf-elixir · GitHub.

3 Likes