-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
Environment
- Elixir & Erlang/OTP versions (elixir --version): Elixir 1.10.4 (compiled with Erlang/OTP 21)
Current behavior
I get a strange dialyzer warning when writing a custom mix task.
I don't know if it is really a bug or if is related to elixir so feel free to close it.
I want the task to exit with different exit codes based on the error, this is a minimal example showing my issue
defmodule A do
def a do
with :ok <- File.cp("a", "b"),
{:ok, _} <- File.rm_rf("a") do
:ok
else
{:error, _err} ->
IO.puts("1")
exit({:shutdown, 1})
_ ->
IO.puts("2")
exit({:shutdown, 2})
end
end
endand this is the warning I get on the File.cp line
The pattern can never match the type.
Pattern:
{:error, __err}
Type:
{:error, atom(), binary()}
The warning is related to the use of :erlang.exit/1, removing those calls the warning disappears. It seems that after encountering an :erlang.exit/1 dialyzer stops and doesn't see the next clauses of the else.
I can remove the warning by moving the :erlang.exit/1 call in a case statement but I was wondering why this happens and if it can be some sort of bug.
defmodule A do
def a do
with :ok <- File.cp("a", "b"),
{:ok, _} <- File.rm_rf("a") do
:ok
else
{:error, _err} -> {:error, 1}
_ -> {:error, 2}
end
|> case do
:ok -> :ok
{:error, exit_code} -> exit({:shutdown, exit_code})
end
end
endExpected behavior
No dialyzer warnings
Metadata
Metadata
Assignees
Labels
No labels