Proposal: show function headers/diffs for FunctionClauseErrors

51 views
Skip to first unread message

Bob

unread,
Feb 1, 2017, 6:26:09 AM2/1/17
to elixir-lang-core
"No function clause matching X" errors are generally quite unclear. It'd be nice if all failing function clauses were shown, and even nicer if these clauses were diffed against the actual arguments.

I don't know much about the internals of Elixir, but I don't think a list of function clauses is available at runtime. A possible workaround might be to recompile the module in question, hooking into @on_definition to record the clauses.

José Valim

unread,
Feb 1, 2017, 6:34:30 AM2/1/17
to elixir-l...@googlegroups.com
There is an open issue to provide such feature. It is actually quite complex to implement because you need to reimplement the pattern matching algorithm, except it should go step by step and give feedback along the way. It is also something you likely don't want to run in production, so we need a way to disable such checks when building releases or similar.




José Valim
Skype: jv.ptec
Founder and Director of R&D

On Wed, Feb 1, 2017 at 12:26 PM, Bob <ben.bob....@gmail.com> wrote:
"No function clause matching X" errors are generally quite unclear. It'd be nice if all failing function clauses were shown, and even nicer if these clauses were diffed against the actual arguments.

I don't know much about the internals of Elixir, but I don't think a list of function clauses is available at runtime. A possible workaround might be to recompile the module in question, hooking into @on_definition to record the clauses.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/cc7322d5-61e9-46bf-b3c6-5ca1a3e64e61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bob

unread,
Feb 1, 2017, 8:09:32 AM2/1/17
to elixir-lang-core, jose....@plataformatec.com.br
> you need to reimplement the pattern matching algorithm

Just wondering, is this necessary because it's impossible to list the function clauses or because there's no straightforward way to turn a function clause into one hand of a pattern match?

Given the function clause and the list of arguments, 


On Wednesday, February 1, 2017 at 12:34:30 PM UTC+1, José Valim wrote:
There is an open issue to provide such feature. It is actually quite complex to implement because you need to reimplement the pattern matching algorithm, except it should go step by step and give feedback along the way. It is also something you likely don't want to run in production, so we need a way to disable such checks when building releases or similar.




José Valim
Skype: jv.ptec
Founder and Director of R&D

On Wed, Feb 1, 2017 at 12:26 PM, Bob <ben.bob....@gmail.com> wrote:
"No function clause matching X" errors are generally quite unclear. It'd be nice if all failing function clauses were shown, and even nicer if these clauses were diffed against the actual arguments.

I don't know much about the internals of Elixir, but I don't think a list of function clauses is available at runtime. A possible workaround might be to recompile the module in question, hooking into @on_definition to record the clauses.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

José Valim

unread,
Feb 1, 2017, 8:20:41 AM2/1/17
to Bob, elixir-lang-core
 
Just wondering, is this necessary because it's impossible to list the function clauses or because there's no straightforward way to turn a function clause into one hand of a pattern match?

It is necessary if we want to do things such as "diffing". For example, if we can't match a clause because a map is missing a field, we should tell the field that is missing when we implement such feature. This "diffing" or "explaining" requires reimplementing pattern matching.

Bob

unread,
Feb 1, 2017, 8:58:58 AM2/1/17
to elixir-lang-core, ben.bob....@gmail.com, jose....@plataformatec.com.br
Ah, I mistakenly believed that ExUnit already highlighted failing pattern matches, hence my confusion. Thanks for the explanation.

Michał Muskała

unread,
Feb 1, 2017, 9:19:14 AM2/1/17
to elixir-l...@googlegroups.com
When erlang abstract code is compiled to the erlang core code there are explicit catch-all clauses added to case expressions, that raise the unmatched error added (function clauses are compiled to case at that point as well). We could think about doing something similar in the current compiler, although it might be one of the things that would be made simpler if elixir compiled to core directly. 

Michał.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Lsd7YPArUjFXjAsbxm%2BQ-CxxvBwOJhSZ%3DJQqU%2BO0svKw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages