I have the following code:
@spec test_pass(String.t) :: (:failed | {:ok, map()})
def test_pass(pass) do
db_user = %{password_hash: @hash_for_foo}
with {:ok, ^db_user} <- Comeonin.Argon2.check_pass(db_user, pass) do
{:ok, db_user}
else
_ -> :failed
end
end
And Dyalizer is giving me the "can never match error":
⟨my_file⟩.ex:25: The pattern {'ok', _} can never match the type {'error',<<_:64,_:_*8>>}
My Question is, why? I know it can't match, and I actually don't care, that's why I'm using with
in the first place. All of the non-matching cases are handled in the else
.
How can I change my code that dialyzer
will be satisfied?
I'm not looking for @dialyzer {:nowarn_function, …}
. I already tried it with a {:error, _} -> …
expression in the else
body but no avail.
Erlang/Elixir version (elixir -v
):
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.6.1 (compiled with OTP 19)
Argon.check_pass/2
is external, from Comeonein
.
I checked comeonin
out, and ran mix dialixier
on it and it reported several no local return
errors.