I'm cross-posting this to the Elixir forums and was discussing it on 
discord so I apologize if you see this twice.

I’m having a bit of an intermittent issue with deriving a protocol with an 
Any implementation and I’m not sure how to debug the issue or even 
reproduce consistently enough to file a bug so I thought I’d ask for 
suggestions here first.

I have a complex project where this appears. Unfortunately this project 
isn’t open source yet but hopefully soon as it would be much easier to 
share code to debug this weird issue.  I have successfully implemented 
about 8 protocols so far (although none with deriving `Any`).  I was 
creating a textbook Any protocol to derive from similar to 
https://hexdocs.pm/elixir/protocols.html#deriving .

At first this bug arose when I stuck a dbg() statement into the Any 
implementation in order to debug an issue I was getting. When I did this 
and tried to derive the protocol for a given module struct I’d get 
something similar to:

```
== Compilation error in file lib/kerilixir/KERI/events/receipt_event.ex ==
** (ArgumentError) could not load module Said.Saidifiable due to reason 
:nofile, cannot derive Said.Saidifiable for Kerilixir.Keri.ReceiptEvent
(elixir 1.19.5) lib/protocol.ex:331: Protocol.assert_protocol!/2
(elixir 1.19.5) lib/protocol.ex:1104: Protocol.derive/4
(stdlib 7.2) lists.erl:2641: :lists.foreach_1/2
(elixir 1.19.5) lib/protocol.ex:1097: Protocol.*derive*/3
lib/kerilixir/KERI/events/receipt_event.ex:22: (module)
```

When I removed the dbg() statement, removed the @derive from the struct, 
recompiled, added back the derive (without the dbg statement) the protocol 
would derive successfully. Adding the debug statement back would reproduce 
the error consistently.

Then somehow yesterday in fooling around with it I got the compilation and 
tests to pass with dbg() statement allowing me to troubleshoot the function 
call and fix the bug. Now when trying to derive this protocol for other 
structs I’m getting this error consistently again. At this point, I don’t 
have the dbg() calls anymore in the Any implementation but am still getting 
the :nofile error.

It seems like this is an issue in consolidation or compilation or something 
else that I don’t understand and so I’m reaching out for any ideas or even 
places to look in beginning to debug this. Its frustrating because the 
pattern of having a default protocol will work for most of these structs 
but then a few will be exceptions that will need custom implementations.

It did seem to happen with mix test more than mix compile but maybe that's 
all in my head. Now its just occurring over and over with mix compile.

I tried to create a simpler example of the file structure and test 
structure I’m running here (tests fail but not the :nofile error) but 
failed to reproduce my error in this simpler example. 
https://github.com/daidoji/simple_example

*tl;dr something weird is happening in consolidation or compilation process 
and my protocol isn’t getting derived even though it should. Looking for 
ideas on how to troubleshoot this intermittent error.*

-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/elixir-lang-core/dad8f51d-6689-4967-8474-ab8e2ca78c63n%40googlegroups.com.

Reply via email to