jeremyjh / dialyxir

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

Undefined function Mix.env/0 #403

Closed ghost closed 4 years ago

ghost commented 4 years ago

Environment

Tested on three different machines/environments.

Elixir 1.10.4 (compiled with Erlang/OTP 22)


2) Windows 10 Pro 1909 with Elixir installer

Erlang/OTP 23 [erts-11.0] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1]

Elixir 1.10.4 (compiled with Erlang/OTP 21)


3) Elixir docker image

Erlang/OTP 22 [erts-10.7.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.10.4 (compiled with Erlang/OTP 22)


* Which version of Dialyxir are you using? (cat mix.lock | grep dialyxir):
1.0.0

### Current behavior
When running `mix dialyzer` on my phoenix project with `MIX_ENV=dev`, I get on all three environments the same error:

Total errors: 1, Skipped: 0, Unnecessary Skips: 0 done in 0m6.08s :0:unknown_function Function Mix.env/0 does not exist.


done (warnings were emitted) Halting VM with exit status 2


Format raw says only (unhelpful-wise):

{:warn_unknown, {[], 0}, {:unknown_function, {Mix, :env, 0}}}



### Expected behavior
No errors. Project compiles without any errors or warnings and runs without any problems. All `Mix.env()` usages are valid, I'm running a mix release without any crashes.
jeremyjh commented 4 years ago

If you are using mix application at runtime, you need to included it in your extra_applications key in your mix.exs. We're not encouraged to use Mix at runtime in our applications, since it is a build tool. If you are using mix release you probably don't want to be using Mix.env().

ghost commented 4 years ago

I'm not running Mix at runtime, it's used completely at compile time for conditional compilation.

romenigld commented 1 year ago

I fixed the Dialyzer warnings with the unquote macro doing this:

if unquote(Mix.env() == :prod) do