nimskull
nimskull copied to clipboard
Compiler crash (missing body) with declaration of inline proc
Traceback:
/home/user/nimskull/compiler/nim.nim(154) nim
/home/user/nimskull/compiler/nim.nim(89) handleCmdLine
/home/user/nimskull/compiler/front/main.nim(539) mainCommand
/home/user/nimskull/compiler/front/main.nim(491) compileToBackend
/home/user/nimskull/compiler/front/main.nim(217) commandCompileToC
/home/user/nimskull/compiler/backend/cbackend.nim(406) generateCode
/home/user/nimskull/compiler/backend/cbackend.nim(478) generateCode
/home/user/nimskull/compiler/backend/cbackend.nim(289) emit
/home/user/nimskull/lib/system/assertions.nim(38) failedAssertImpl
/home/user/nimskull/lib/system/assertions.nim(28) raiseAssert
/home/user/nimskull/lib/system/fatal.nim(50) sysFatal
Error: unhandled exception: /home/user/nimskull/compiler/backend/cbackend.nim(289, 10) `prc.body.code != nil` missing body [AssertionDefect]
I can only trigger this bug with 4 separate files. Minimum example is attached (try to compile test.nim
).
missing_body.tar.gz
I think the key lines are these:
proc foo*[T](utype: typedesc[T]): var seq[T] {.inline.}
import ./bar
proc foo*[T](utype: typedesc[T]): var seq[T] {.inline.} = discard
Notice how the proc is declared before importing bar
because it's part of a cyclic module import and both modules are meant to be able to use each other procs.
A workaround is easy. The biggest problem with this bug is the lack of any feedback on what the problem might be. Disallowing this kind of use of inline functions is fine, but it should have an appropriate error message.