Dialyzer error: "The pattern can never match the type."

case foo do
  {:pass, _} ->
    bar(
      arg1,
      arg2,
      arg3
    )

  _ ->
    baz(arg)
end

Dialyzer error:

The pattern can never match the type.

Pattern:
{:pass, _}

Type:
[any()]

How should this issue be addressed?

Looks like dialyzer thinks that foo will always be a list and the tuple case will never match that. How to fix it depends on the specs (if they exist) and the places where this function is called.

1 Like

Yep, as @aziz wrote, dialyzer determines that foo is always a list of one element (the type [any()] is a list of one element of any type). Therefore, the first clause of your case, where you match a tuple, can never match.

In order to solve it you have to figure out if you expected foo to be always a list. If yes, then the first clause of the case is useless and can be removed, or changed to match a list if that’s what you wanted. If not, then you need to figure out why it is the case that foo is always a list. Maybe the value you expected is wrapped in a list?

1 Like