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

FunctionClauseError for a parameterized type referencing another parameterized type #14

Closed
nicholasjhenry opened this issue Nov 8, 2019 · 1 comment · Fixed by #20
Closed
Labels
bug Something isn't working

Comments

@nicholasjhenry
Copy link

Should Hammox support parameterized union type consisting of custom types?

defmodule Result do
  @type ok(any) :: {:ok, any}
  @type error(any) :: {:error, any}

  @typedoc "the two-track type"
  @type t(a, b) :: ok(a) | error(b)
end

I get the following error:

     ** (FunctionClauseError) no function clause matching in Hammox.TypeEngine.match_type/2

     The following arguments were given to Hammox.TypeEngine.match_type/2:

         # 1
         :foo

         # 2
         {:var, 7, :a}

     Attempted function clauses (showing 10 out of 91):

         def match_type(value, {:type, _, :union, union_types} = union) when is_list(union_types)
         def match_type(_value, {:type, _, :any, []})
         def match_type(value, {:type, _, :none, []} = type)
         def match_type(value, {:type, _, :atom, []}) when is_atom(value)
         def match_type(value, {:type, _, :atom, []} = type)
         def match_type(value, {:type, _, :map, :any}) when is_map(value)
         def match_type(value, {:type, _, :pid, []}) when is_pid(value)
         def match_type(value, {:type, _, :pid, []} = type)
         def match_type(value, {:type, _, :port, []}) when is_port(value)
         def match_type(value, {:type, _, :port, []} = type)

     code: HammoxPlayground.Mock.perform(Decimal.new("0.992"))
     stacktrace:
       (hammox) lib/hammox/type_engine.ex:6: Hammox.TypeEngine.match_type/2
       (hammox) lib/hammox/type_engine.ex:100: anonymous fn/1 in Hammox.TypeEngine.match_type/2
       (elixir) lib/enum.ex:2984: Enum.find_value_list/3
       (hammox) lib/hammox/type_engine.ex:99: Hammox.TypeEngine.match_type/2
       (hammox) lib/hammox/type_engine.ex:9: anonymous fn/3 in Hammox.TypeEngine.match_type/2
       (elixir) lib/enum.ex:3325: Enumerable.List.reduce/3
       (elixir) lib/enum.ex:1998: Enum.reduce_while/3
       (hammox) lib/hammox/type_engine.ex:8: Hammox.TypeEngine.match_type/2
       (hammox) lib/hammox.ex:312: Hammox.match_return_value/2
       (hammox) lib/hammox.ex:280: Hammox.match_call/3
       (hammox) lib/hammox.ex:264: anonymous fn/4 in Hammox.check_call/3
       (elixir) lib/enum.ex:3325: Enumerable.List.reduce/3
       (elixir) lib/enum.ex:1998: Enum.reduce_while/3
       (hammox) lib/hammox.ex:263: Hammox.check_call/3
       (hammox) lib/hammox.ex:256: Hammox.protected_code/3
       test/hammox_playground_test.exs:13: (test)
nicholasjhenry added a commit to civilcode/civilcode-ex that referenced this issue Nov 8, 2019
Hammox does not handle this currently so let's make it easier for the
library.

msz/hammox#14
@nicholasjhenry nicholasjhenry changed the title FunctionClauseError for a parameterized union type consisting of custom types FunctionClauseError for a parameterized type referencing another parameterized type Nov 8, 2019
@nicholasjhenry
Copy link
Author

@msz Actually it's simpler than the original issue I posted. I've updated the title to refect this. This is the example that causes the exception:

  defmodule Result do
    @type ok(any) :: any
    @type t(a) :: ok(a)
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants