The following proc forward declaration example compiles: (Taken from https://github.com/nim-lang/Nim/issues/12033)
proc test_proc[T, U](arg1: T, arg2: U): float # All good!
The following does not:
proc meaning[T]( s_expr: T ): Atom # Error: implementation of 'lil_JSchemer.meaning(s_expr: T)' expected
The only difference I notice is that Atom is a variant type that I have defined in the same file. However the following also fails:
proc meaning[T]( s_expr: T ): bool # Error: implementation of 'lil_JSchemer.meaning(s_expr: T)' expected
within which I cannot identify the important difference from the working example. These functions are neither actually defined nor used in the file; I have commented out their usage.
Can you tell me what is different is and why it is wrong?
Secondary Q: Is it possible to have a forward declaration that is not generic [T] ?
These functions are neither actually defined nor used in the file; I have commented out their usage.
It is an error to have "forward declaration" but no "later declaration". I think that is your error.
Yes, you can forward declare non generic function.
Ah, I see now that the supposed "working example" was a red herring. When I comment out the meaning forward declaration, then the compiler complains about test_proc. I had assumed that the declarations would be checked in the order they were written and also that they would both be checked.
Is the idea that the compiler only complains about one missing definition of a forward declaration out of two a design principle for Nim, or is it the side effect of some background optimization work?
If it matters, this was the compiler command used:
nim c -d:release --hints:off --run -o:exec/lil_JSchemer -r lil_JSchemer.nim