defmodule Foo do
if Mix.env() == :prod do
alias Foo.Bar
def foo do
Bar
end
end
end
mix compile in dev env produces the warning:
warning: unused alias Bar
foo.ex:3
No warning.
I don't think we can do anything about this. The body level, including the if block, is analyzed but the content of the function is not, because we never execute the def. You have to set warn: false in those cases.
For anyone coming across this in the future this is the syntax you need to get rid of the warning:
defmodule Foo do
if Mix.env() == :prod do
alias Foo.Bar, warn: false
def foo do
Bar
end
end
end
Just to be sure, is this the same thing here:
defmodule Foo do
use Ecto.Schema
alias Foo.Bar
schema "foo" do
embeds_one :bla, Bla do
embeds_one(:bar, Bar)
end
end
end
Most helpful comment
For anyone coming across this in the future this is the syntax you need to get rid of the warning: