As if it wasn't for my passion for forward proc declarations, now I have an issue with pragmas + forward declarations.
Here is the story:
Any ideas how this can be solved?
Seems like a bug. Pragmas should probably only be triggered for proc implementations.
Either it's a bug in Nim because it triggers pragmas for forward declared proc or it's a bug in memoize which should detect that it's called in a forward-declared context (how?).
My finger would be, you are the first one to use a custom pragma that modifies a proc body on a forward declared proc. I don't know if there are use case to trigger a pragma on a forward declare proc, if not I think Nim should be updated to not do that so that all the existing macros libraries work on forward declared proc.
The macro pragma is actually a macro that takes the proc declaration as it's argument. In the case of a forward declaration it should return the proc unchanged. Instead it adds a body to it turning into a full declaration of the proc. Don't add the memoized pragma to the forward declaration and it should work.
The only time a macro pragma shouldn't return a forward declaration unchanged is when it change's the parameter or return types of a procedure.
I encourage you to look at the source code of memo.nim to see exactly why the macro works the way it does. It's very easy to forget edge cases when creating macros and working with NimNodes. Hopefully as many libraries become more mature alot of these edge cases are taken into account when creating macros.