Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dializer failed pattern match in 'case' clause in 'with' clause #483

Open
ByeongUkChoi opened this issue Mar 10, 2023 · 0 comments
Open

Comments

@ByeongUkChoi
Copy link

ByeongUkChoi commented Mar 10, 2023

Precheck

  • Take a look at the open issues and be sure that your issue is not already covered.
  • Be sure your versions of Dialyxir and Erlex are up to date.

Environment

  • Elixir & Erlang/OTP versions (elixir --version): 1.13.4

  • Which version of Dialyxir are you using? (cat mix.lock | grep dialyxir): 1.2.0

Current behavior

  • Describe current behavior. Include errors, stack traces, and any additional information that might be important here.

dializer succeeds in Foo.test_1/0 But Foo.test_2/0 failed

defmodule Foo do
  def test_1() do
    with {:ok, _} <- aa(),
         {:ok, _} <- bb(),
         {:ok, _} <- cc() do
      :success
    else
      nil -> :error_c
      {:error, _} -> :error_a
      {:error, _, _} -> :error_b
    end
  end

  def test_2() do
    with {:ok, _} <- aa(),
         {:ok, _} <- bb(),
         {:ok, _} <- cc() do
      :success
    else
      nil ->
        :error_c

      err ->
        case err do
          {:error, _} -> :error_a
          {:error, _, _} -> :error_b
        end
    end
  end

  defp aa() do
    if Enum.random(0..1) == 1 do
      {:ok, 1}
    else
      {:error, 2}
    end
  end

  defp bb() do
    if Enum.random(0..1) == 1 do
      {:ok, 3}
    else
      {:error, 4, 5}
    end
  end

  defp cc() do
    if Enum.random(0..1) == 1 do
      {:ok, 6}
    else
      nil
    end
  end
end

Expected behavior

  • A short description of the expected behavior.

Everyone needs to succeed.
all functions(test_1, test_2) work successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant