rewire icon indicating copy to clipboard operation
rewire copied to clipboard

rewire doesn't work through `use`

Open jvantuyl opened this issue 2 years ago • 2 comments

When rewiring a module in a test, we were noticing that it wasn't replacing all of the occurrences of a module. We eventually tracked down that the module in question was being brought in by a use macro. When traversing the AST, it appears that the use special form doesn't get expanded for rewire, so anything that brings in is left with the original module.

jvantuyl avatar Aug 22 '23 16:08 jvantuyl

Thank you for the bug report, @jvantuyl! I was able to reproduce the problem: https://github.com/stephanos/rewire/pull/21

But to be honest, I'm not quite sure how to solve it yet. I haven't touched Elixir in 1+ year and am not super familiar with the macro system. I'm gonna give it another try soon. But in the meantime, if you know how to expand the __using__ macro, please give it a go or let me know!

stephanos avatar Aug 23 '23 01:08 stephanos

Unfortunately, I don't know how to do this. I'm pretty sure that we just have to recurse some way if we traverse into a use invocation. But it's just deep enough in the weeds that I'm not really sure how to do it just yet. :(

jvantuyl avatar Sep 12 '23 07:09 jvantuyl