There still seems to be a problem when this function is being used with “boolean” operators, for example:
defmodule Types do
def prod?, do: unquote(Mix.env() == :prod)
def a_or_b do
if Types.prod?() and :rand.uniform() > 0.5 do
:a
else
:b
end
end
end
warns
warning: the following conditional expression will always evaluate to dynamic(false):
Types.prod?()
typing violation found at:
│
9 │ if Types.prod?() and :rand.uniform() > 0.5 do
│ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
│
└─ lib/types.ex:9: Types.a_or_b/0
Rewriting the caller like this seems to work but …
def a_or_b do
if Types.prod?() do
if :rand.uniform() > 0.5 do
:a
end
end || :b
end
The fix right now only works when comparing constants. Because you encapsulate it in a function, it no longer works, but it would work if you did @env == :dev.