Skip to content

no function clause matching in Gradient.ElixirExpr.pp_guards/1 #171

Open
@alanvardy

Description

@alanvardy

Hello,

I've been really enjoying using gradient, thank you for the work! I've encountered this error today when running mix gradient

(FunctionClauseError) no function clause matching in Gradient.ElixirExpr.pp_guards/1

    The following arguments were given to Gradient.ElixirExpr.pp_guards/1:

        # 1
        [[{:call, [generated: true, location: 486], {:remote, [generated: true, location: 486], {:atom, [generated: true, location: 486], :erlang}, {:atom, [generated: true, location: 486], :is_atom}}, [{:var, [generated: true, location: 486], :_@2}]}, {:op, [generated: true, location: 486], :"=/=", {:var, [generated: true, location: 486], :_@2}, {:atom, [generated: true, location: 486], nil}}, {:op, [generated: true, location: 486], :"=/=", {:var, [generated: true, location: 486], :_@2}, {:atom, [generated: true, location: 486], true}}, {:op, [generated: true, location: 486], :"=/=", {:var, [generated: true, location: 486], :_@2}, {:atom, [generated: true, location: 486], false}}]]

    Attempted function clauses (showing 2 out of 2):

        def pp_guards([])
        def pp_guards([[guard]])

    Gradient.ElixirExpr.pp_guards/1
    lib/gradient/elixir_expr.ex:310: Gradient.ElixirExpr.pp_case_clause/1
    (elixir 1.14.2) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.14.2) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
    lib/gradient/elixir_expr.ex:248: Gradient.ElixirExpr.pp_clauses/2
    lib/gradient/elixir_expr.ex:207: Gradient.ElixirExpr.pp_expr/1
    lib/gradient/elixir_expr.ex:154: Gradient.ElixirExpr.pp_expr/1
    (elixir 1.14.2) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
[[Command exited with 1]]

The error occurs three times within the same module and nowhere else. I believe that the issue stems from my custom guard which is used in three different functions.

Here is the guard definition

  @max_integer 32_767

  defguard pos_int(integer) when integer < @max_integer and integer > 0

And here is an example of it in use

  @doc false
  @spec kills(Match.t(), puuid) :: res(non_neg_integer)
  def kills(match, puuid) do
    case Fetch.player(match, puuid) do
      {:ok, %Player{stats: %PlayerStats{kills: kills}}} when pos_int(kills) ->
        {:ok, kills}

      {:ok, %Player{}} ->
        {:ok, 0}

      {:error, error} ->
        {:error, error}
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions