arjan / decorator

Function decorators for Elixir
MIT License
386 stars 21 forks source link

Fix for @decorate_all when function clauses are separated. #38

Closed whilefalse closed 4 years ago

whilefalse commented 4 years ago

Previously, when using @decorate_all, if you had defined a function that had multiple clauses, but the clauses weren't next to each other, we would only redefine the second clause, thus the first clause would be entirely lost.

I realise it's bad practice to have clauses not next to each other, but the failure mode was very confusing. It would give a FunctionClauseError saying the function clause couldn't match. But upon looking in the source code, that clause was clearly there.

I've fixed this by checking for all previous definitions when deciding whether to output the overridable clause.

I've added a test to show the problem. If you run that on the previous code it will fail because the first clause is ommitted.

Thanks

By the way thanks for all your hard work, the library is really useful!

arjan commented 4 years ago

Thanks for the fix! Published 1.3.2