OvermindDL1 / protocol_ex

Elixir Extended Protocol
https://hex.pm/packages/protocol_ex
48 stars 5 forks source link

Permit defining functions that are not in the protocol #22

Closed jjl closed 6 years ago

jjl commented 6 years ago

Using a def that doesn't exist in the protocol gives me this rather unintuitive error:

== Compilation error in file lib/docker_schema.ex ==
** (ArgumentError) argument error
    :erlang.length(nil)
    lib/protocol_ex.ex:230: anonymous fn/2 in ProtocolEx.defimplEx_do/6
    (elixir) lib/macro.ex:277: anonymous fn/4 in Macro.do_traverse_args/4
    (elixir) lib/enum.ex:1397: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir) lib/enum.ex:1397: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir) lib/macro.ex:243: Macro.do_traverse/4
    lib/protocol_ex.ex:228: ProtocolEx.defimplEx_do/6
    lib/docker_schema.ex:4: (file)

Line 4 is the defimpl_ex line. I can make them defp, but it'd be nice for my tests if I could see them and putting them in another module seems a bit overkill

OvermindDL1 commented 6 years ago

Hmm, do you have an example? I added functions that weren't in the protocol to my implementation tests and they worked fine so it is probably some specific syntax that I need to fix up. :-)

Actually I might have found it, the issue is that I'm guessing that you are creating an argumentless function definition (def blah, do: ... instead of def blah(), do:)? The formatter would fix that to have parenthesis as the lack there-of is considered poor form according to the syntax standards. However it looks like an easy fix, thus it should be fixed in 0.3.25 if you want to try it? :-)

jjl commented 6 years ago

I'm not sure where this release is (not in hex, nor in a tag called "0.3.25'), but master passes.

OvermindDL1 commented 6 years ago

It is, I just forgot to hit Y so it took a while to go through. ^.^;

0.3.26 is out now too with support for printing the protocol source (see readme for a caveat) as requested by @jjl too!