Closed
Description
Nim Version
Nim Compiler Version 2.2.4 [Linux: amd64]
Compiled at 2025-06-14
Copyright (c) 2006-2025 by Andreas Rumpf
git hash: 7701b3c
active boot switches:
Description
This crashes the compiler:
type X = object
proc `=destroy`(x: X) {.error.} =
discard
proc main() =
var x = X()
main()
Current Output
Traceback (most recent call last)
/src/Nim/compiler/nim.nim(169) nim
/src/Nim/compiler/nim.nim(124) handleCmdLine
/src/Nim/compiler/main.nim(324) mainCommand
/src/Nim/compiler/main.nim(290) compileToBackend
/src/Nim/compiler/main.nim(153) commandCompileToC
/src/Nim/compiler/pipelines.nim(320) compilePipelineProject
/src/Nim/compiler/pipelines.nim(239) compilePipelineModule
/src/Nim/compiler/pipelines.nim(184) processPipelineModule
/src/Nim/compiler/pipelines.nim(25) processPipeline
/src/Nim/compiler/cgen.nim(2436) genTopLevelStmt
/src/Nim/compiler/cgen.nim(1265) genProcBody
/src/Nim/compiler/ccgstmts.nim(1951) genStmts
/src/Nim/compiler/ccgexprs.nim(3580) expr
/src/Nim/compiler/ccgexprs.nim(3236) genStmtList
/src/Nim/compiler/ccgstmts.nim(1951) genStmts
/src/Nim/compiler/ccgexprs.nim(3542) expr
/src/Nim/compiler/ccgcalls.nim genCall
/src/Nim/compiler/ccgcalls.nim(893) genAsgnCall
/src/Nim/compiler/ccgcalls.nim(475) genPrefixCall
/src/Nim/compiler/cgen.nim(804) initLocExpr
/src/Nim/compiler/ccgexprs.nim(3461) expr
/src/Nim/compiler/cgen.nim(1542) genProc
/src/Nim/compiler/cgen.nim(1516) genProcNoForward
/src/Nim/compiler/cgen.nim(1287) genProcAux
/src/Nim/compiler/injectdestructors.nim(1322) injectDestructorCalls
/src/Nim/compiler/injectdestructors.nim(955) p
/src/Nim/compiler/injectdestructors.nim(572) pVarTopLevel
/src/Nim/compiler/injectdestructors.nim(256) genDestroy
/src/Nim/compiler/injectdestructors.nim(251) genOp
/src/Nim/compiler/injectdestructors.nim(218) checkForErrorPragma
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Expected Output
Complain because =destroy must be injected?
Known Workarounds
No response
Additional Information
My aim was to statically leak check uses of an object defined by an external C library, by marking its importc'd free
method as taking sink X
, and disabling its =copy
& =destroy
hooks.
(Said free
method takes an additional context parameter, so calling it in the destructor would either involve bundling the context with every single object or storing it in TLS - neither is ideal in my case.)