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

Some generated clauses can never match #26

Open
wodow opened this issue Dec 12, 2023 · 2 comments
Open

Some generated clauses can never match #26

wodow opened this issue Dec 12, 2023 · 2 comments

Comments

@wodow
Copy link

wodow commented Dec 12, 2023

Compiling the library results in ~40 warnings like:

warning: this clause cannot match because a previous clause at line 109 always matches
  lib/domainatrex.ex:88

warning: this clause cannot match because a previous clause at line 109 always matches
  lib/domainatrex.ex:88

warning: this clause cannot match because a previous clause at line 109 always matches
  lib/domainatrex.ex:88

I'm not yet sure how to determine which entries in the PSL cause these or whether it's a problem.

@yssoe
Copy link

yssoe commented Aug 30, 2024

Having the same problem, bit annoying in the CI/CD pipeline, is there a quick fix for this? thanks

@axelson
Copy link

axelson commented Dec 14, 2024

I took a look at this. Here's a minimal example of the issue:

defmodule Demo do
  @doc """
      iex> my_match(["com", "customer-oci"])
      :match2plus
      iex> my_match(["com", "customer-oci", "a"])
      :match3
      iex> my_match(["com", "customer-oci", "a", "b"])
      :match4
      iex> my_match(["com", "customer-oci", "a", "b", "c"])
      :match2plus

      iex> my_match(["com", "customer-oci"])
      :match2plus
      iex> my_match(["com", "customer-oci", "oci"])
      :match3
      iex> my_match(["com", "customer-oci", "oci", "b"])
      :match4
      iex> my_match(["com", "customer-oci", "oci", "b", "c"])
      :match2plus

      iex> my_match(["com", "customer-oci"])
      :match2plus
      iex> my_match(["com", "customer-oci", "ocp"])
      :match3
      iex> my_match(["com", "customer-oci", "ocp", "b"])
      :match4
      iex> my_match(["com", "customer-oci", "ocp", "b", "c"])
      :match2plus
  """
  for suffix <- [
        ["com", "customer-oci", "oci", "*"],
        ["com", "customer-oci", "ocp", "*"]
      ] do
    # matches list of length 3
    def my_match([unquote(Enum.at(suffix, 0)), unquote(Enum.at(suffix, 1)), _a]) do
      :match3
    end

    # matches list of length 4
    def my_match([unquote(Enum.at(suffix, 0)), unquote(Enum.at(suffix, 1)), _a, _b]) do
      :match4
    end

    # matches list of length 2+
    def my_match([unquote(Enum.at(suffix, 0)), unquote(Enum.at(suffix, 1)) | _] = _args) do
      :match2plus
    end
  end
end

The problem is that the "same" function head is being defined multiple times (e.g. since only the first two parts of the suffix are used in the match).

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

3 participants