Dialyzer with unmatched case

I’m surprised dialyzer doesn’t complain about the following code. Since fun_b returns either :ok or :error I would hope it would point out that all return values aren’t handled by the case matches.

Am I doing something wrong, or is this just some type of limitation?

def fun_a() do
  case fun_b() do
    :ok -> :ok
  end
end

@spec fun_b :: :ok | :error
def fun_b() do
  case :rand.uniform(2) do
    1 -> :ok
    2 -> :error
  end
end

I had similar question in this post.

TLDR;

@michalmuskala Dialyzer will report errors only if they will always happen, not if they might happen.

@peerreynders Dialyzer assumes you are right until it can prove you wrong.

1 Like

Dialyzer will not complain even if You do

@spec fun_b :: :ok | :error
def fun_b() do
  case :rand.uniform(2) do
    1 -> :okidoki
    2 -> :error
  end
end
1 Like