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

Hammox breaks when there is a @typep #41

Closed
gabrielpra1 opened this issue May 28, 2020 · 1 comment · Fixed by #42
Closed

Hammox breaks when there is a @typep #41

gabrielpra1 opened this issue May 28, 2020 · 1 comment · Fixed by #42
Labels
bug Something isn't working

Comments

@gabrielpra1
Copy link

gabrielpra1 commented May 28, 2020

This code in type_engine.ex accepts only @type:

  defp get_type(type_list, type_name, arity) do
    case Enum.find(type_list, fn {:type, {name, _type, params}} ->
           name == type_name and length(params) == arity
         end) do
      nil -> {:error, {:type_not_found, {type_name, arity}}}
      type -> {:ok, type}
    end
  end

However, Typespecs accepts @type, @typep and @opaque (source). This causes hammox to break:

     ** (FunctionClauseError) no function clause matching in anonymous fn/1 in Hammox.TypeEngine.get_type/3

     The following arguments were given to anonymous fn/1 in Hammox.TypeEngine.get_type/3:

         # 1
         {:typep, {:names, {:remote_type, 133, [{:atom, 0, MapSet}, {:atom, 0, :t}, []]}, []}}

     stacktrace:
       (hammox 0.2.4) lib/hammox/type_engine.ex:695: anonymous fn/1 in Hammox.TypeEngine.get_type/3
       (elixir 1.10.2) lib/enum.ex:3305: Enum.find_list/3
       (hammox 0.2.4) lib/hammox/type_engine.ex:695: Hammox.TypeEngine.get_type/3
       (hammox 0.2.4) lib/hammox/type_engine.ex:656: Hammox.TypeEngine.resolve_remote_type/1
       (hammox 0.2.4) lib/hammox/type_engine.ex:621: Hammox.TypeEngine.match_type/2
       (hammox 0.2.4) lib/hammox.ex:312: Hammox.match_return_value/2
       (hammox 0.2.4) lib/hammox.ex:280: Hammox.match_call/3
       (hammox 0.2.4) lib/hammox.ex:264: anonymous fn/4 in Hammox.check_call/3
       (elixir 1.10.2) lib/enum.ex:3686: Enumerable.List.reduce/3
       (elixir 1.10.2) lib/enum.ex:2161: Enum.reduce_while/3
       (hammox 0.2.4) lib/hammox.ex:263: Hammox.check_call/3
       (hammox 0.2.4) lib/hammox.ex:256: Hammox.protected_code/3

In my case, I'm using Ecto.Multi.t() as the return value of a function, and this structure defines @typep: https://github.com/elixir-ecto/ecto/blob/v3.4.4/lib/ecto/multi.ex#L133

@msz msz added the bug Something isn't working label May 28, 2020
@msz
Copy link
Owner

msz commented May 28, 2020

Thanks for the report! This definitely needs fixing.

msz added a commit that referenced this issue May 30, 2020
Fixes #41.

Hammox blows up when encountering `@typep` and `@opaque`. For now we
will treat them like any other type.

Further work on opaque types in
msz added a commit that referenced this issue May 30, 2020
Fixes #41.

Hammox blows up when encountering `@typep` and `@opaque`. For now we
will treat them like any other type.

Further work on opaque types in #43.
@msz msz closed this as completed in #42 May 30, 2020
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
Development

Successfully merging a pull request may close this issue.

2 participants