jeremyjh / dialyxir

Mix tasks to simplify use of Dialyzer in Elixir projects.
Apache License 2.0
1.68k stars 142 forks source link

Dialyxir attempts to load transitive optional dependencies #502

Closed kipcole9 closed 10 months ago

kipcole9 commented 1 year ago

Environment

Current behavior

Dialyxir is issuing warnings that it can't load applications that are transitive optional dependencies. An example using the ex_cldr lib:

kip@Kips-MacBook-Pro cldr % asdf current
elixir          1.15.0-rc.0-otp-26 /Users/kip/Development/cldr/.tool-versions
erlang          26.0            /Users/kip/Development/cldr/.tool-versions
rust            stable          /Users/kip/.tool-versions
kip@Kips-MacBook-Pro cldr % mix dialyzer
Finding suitable PLTs
Checking PLT...
Error loading castore, dependency list may be incomplete.
 {~c"no such file or directory", ~c"castore.app"}
Error loading certifi, dependency list may be incomplete.
 {~c"no such file or directory", ~c"certifi.app"}
[:asn1, :castore, :certifi, :cldr_utils, :compiler, :crypto, :decimal, :earmark_parser, :eex, :elixir, :ex_doc, :ex_unit, :expo, :gettext, :inets, :jason, :kernel, :logger, :makeup, :makeup_elixir, :makeup_erlang, :mix, :nimble_parsec, :public_key, :ssl, :stdlib, :sweet_xml, :xmerl]
PLT is up to date!
ignore_warnings: .dialyzer_ignore_warnings

Starting Dialyzer
[
  check_plt: false,
  init_plt: ~c"/Users/kip/Development/cldr/_build/dev/dialyxir_erlang-26.0_elixir-1.15.0-rc.0_deps-dev.plt",
  files: [~c"/Users/kip/Development/cldr/_build/dev/lib/ex_cldr/ebin/Elixir.Cldr.LanguageTag.Chars.Cldr.LanguageTag.U.beam",
   ~c"/Users/kip/Development/cldr/_build/dev/lib/ex_cldr/ebin/Elixir.Cldr.Normalize.CalendarEra.beam",
   ~c"/Users/kip/Development/cldr/_build/dev/lib/ex_cldr/ebin/Elixir.Cldr.NoParentError.beam",
   ~c"/Users/kip/Development/cldr/_build/dev/lib/ex_cldr/ebin/Elixir.Cldr.UnknownFormatError.beam",
   ~c"/Users/kip/Development/cldr/_build/dev/lib/ex_cldr/ebin/Elixir.Mix.Tasks.Cldr.Install.Locales.beam",
   ...],
  warnings: [:unknown]
]
Total errors: 0, Skipped: 0, Unnecessary Skips: 0
done in 0m14.38s
done (passed successfully)

The libs :castore and :certifi are optional dependencies of cldr_utils. cldr_utils is a required dependency of ex_cldr.

The warning messages are unique to Elixir 1.15 / OTP 26.

I don’t see this output for any other combinations I’ve tried:

Per this comment it seems reasonable that the addition of an optional_dependencies config key to .app files in OTP 24 and now the building of that config key in Elixir 1.15 may be part of the issue. The relevant code in dialyxir seems to be: https://github.com/jeremyjh/dialyxir/blob/e9556460bc130287dd6687ab02041634ac827913/lib/dialyxir/project.ex#L383

Expected behavior

No warnings are issues when attempting to load transitive optional dependencies.

jeremyjh commented 1 year ago

@kipcole9 Thanks for the well-researched report, and thanks for your work on cldr & money. Will take a look.

tomtaylor commented 1 year ago

Does anyone know if there's a workaround for this at the moment?

dvic commented 1 year ago

Does anyone know if there's a workaround for this at the moment?

Not sure if this helps but linking from the original discussion: https://elixirforum.com/t/elixir-v1-15-0-rc-0-released/56019/28 the suggestion made by Jose:

When they traverse dependencies, they need to include the parent’s optional applications and not log an error if the dependency you cannot load is optional. But, from looking at the code, the warning causes no harm either.

carlogilmar commented 1 year ago

Hi! After upgrade a project with Elixir 1.15.0-otp-26 with Erlang 26.0.1, and after fix the problem with dialyzer (I had to include prune_code_paths: false in mix.exs), I got similar errors, dialyzer works, but I'm worried about all of this warnings:

image

jeremyjh commented 10 months ago

Fixed in https://github.com/jeremyjh/dialyxir/pull/514

kipcole9 commented 10 months ago

Thank you very much @jeremyjh - and for maintaining such an important library. Really appreciated. Even if it still does my head in from time to time!

jeremyjh commented 10 months ago

Published to hex in 1.14