Dialyxir.Warnings.UnmatchedReturn (Dialyxir v1.4.2) View Source

The invoked expression returns a union of types and the call does not match on its return types using e.g. a case or wildcard.

Example

defmodule Example do
  require Integer

  def ok() do
    n = :rand.uniform(100)

    multiple_returns(n)

    :ok
  end

  defp multiple_returns(n) do
    if Integer.is_even(n) do
      :ok
    else
      {:error, "error"}
    end
  end
end

This would NOT result in a warning:

defmodule Example do
  require Integer

  def ok() do
    n = :rand.uniform(100)

    multiple_returns(n)

    :ok
  end

  defp multiple_returns(n) do
    if Integer.is_even(n) do
      :ok
    else
      :error
    end
  end
end