msz/hammox

Type guards in specs not supported

msz opened this issue · 1 comments

msz commented

It is possible to define guards in function typespecs. However, trying to use Hammox with such typespecs will cause a MatchError involving a :bounded_fun type tuple similar to this one:

 ** (MatchError) no match of right hand side value: {:type, 518, :bounded_fun, [{:type, 518, :fun, [{:type, 518, :product, [{:ann_type, 518, [{:var, 518, :request}, {:type, 518, :term, []}]}, {:remote_type, 0, [{:atom, 0, GenServer}, {:atom, 0, :from}, []]}, {:ann_type, 518, [{:var, 518, :state}, {:type, 518, :term, []}]}]}, {:type, 520, :union, [{:type, 519, :tuple, [{:atom, 0, :reply}, {:var, 519, :reply}, {:var, 519, :new_state}]}, {:type, 520, :tuple, [{:atom, 0, :reply}, {:var, 520, :reply}, {:var, 520, :new_state}, {:type, 520, :union, [{:type, 520, :timeout, []}, {:atom, 0, :hibernate}, {:type, 0, :tuple, [{:atom, 0, :continue}, {:type, 520, :term, []}]}]}]}, {:type, 0, :tuple, [{:atom, 0, :noreply}, {:var, 521, :new_state}]}, {:type, 522, :tuple, [{:atom, 0, :noreply}, {:var, 522, :new_state}, {:type, 522, :union, [{:type, 522, :timeout, []}, {:atom, 0, :hibernate}, {:type, 0, :tuple, [{:atom, 0, :continue}, {:type, 522, :term, []}]}]}]}, {:type, 523, :tuple, [{:atom, 0, :stop}, {:var, 523, :reason}, {:var, 523, :reply}, {:var, 523, :new_state}]}, {:type, 524, :tuple, [{:atom, 0, :stop}, {:var, 524, :reason}, {:var, 524, :new_state}]}]}]}, [{:type, 518, :constraint, [{:atom, 518, :is_subtype}, [{:var, 518, :reply}, {:type, 525, :term, []}]]}, {:type, 518, :constraint, [{:atom, 518, :is_subtype}, [{:var, 518, :new_state}, {:type, 525, :term, []}]]}, {:type, 518, :constraint, [{:atom, 518, :is_subtype}, [{:var, 518, :reason}, {:type, 525, :term, []}]]}]]}
                 (hammox 0.4.0) lib/hammox.ex:466: Hammox.arg_typespec/2
                 (hammox 0.4.0) lib/hammox.ex:375: anonymous fn/2 in Hammox.match_args/2
                 (elixir 1.11.2) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
                 (hammox 0.4.0) lib/hammox.ex:374: Hammox.match_args/2
                 (hammox 0.4.0) lib/hammox.ex:361: Hammox.match_call/3
                 (hammox 0.4.0) lib/hammox.ex:346: anonymous fn/4 in Hammox.check_call/3
                 (elixir 1.11.2) lib/enum.ex:3764: Enumerable.List.reduce/3
                 (elixir 1.11.2) lib/enum.ex:2231: Enum.reduce_while/3
                 (hammox 0.4.0) lib/hammox.ex:345: Hammox.check_call/3
                 (hammox 0.4.0) lib/hammox.ex:338: Hammox.protected_code/3
                 (stdlib 3.13.2) gen_server.erl:706: :gen_server.try_handle_call/4
                 (stdlib 3.13.2) gen_server.erl:735: :gen_server.handle_msg/6
                 (stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

This is a public feature of Elixir typespecs and needs to be supported.

I just ran into this too. Do you have any plans to work on this?