fireproofsocks
Warnings using defoverridable - warning: this clause for foo/1 cannot match because a previous clause at line 8 always matches
I seem to have stumbled into something similar to what was mentioned in this thread: Function overriding causes warning
however, I can’t spot the trouble.
I have a “base” module that provides some default implementations of functions (i.e. not functions that are optional in any way that could be notated via @optional_callbacks). 90% of the time, the default implementation is what’s used. But when I do need to override the one of these functions, I keep seeing warnings, .e.g
warning: this clause for foo/1 cannot match because a previous clause at line 8 always matches
lib/my_app/foo.ex:130
My tests are passing – the proper code is getting executed. Can anyone shed light on the source of the warning? I have the proper use statement in my modules, so I’m wondering if there’s something else I’ve missed.
Most Liked
LostKobrakai
You’ll want to use @before_compile to put the default implementations at the end of the module instead of at the top (where use … is located). Then any custom implementation comes before your generated one. If you still get a warning you can use generated: true on the quote do block with the generated default implementation to prevent that.
beepbeepbopbop
Can you provide a working example? It’s hard to tell what’s going on here, but I suspect its due to how the use macro is being expanded.







