An additional piece of information. I passed the equivalent source code to the
`dumpCompiledCode` macro instead of the output from `refObjectDestructor`:
dumpCompiledCode:
proc `=destroy`(x: typeof(Marker()[])) =
`=destroy`(x.tref)
Run
The result was identical. The original code was printed, with the addition of a
`raises` pragma, and then the compiler crashed.
proc `=destroy`(x: typeof(Marker()[])) {.raises: [].} =
`=destroy`(x.tref)
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)
Run
So the problem seems to be with the `dumpCompiledCode` macro.
macro dumpCompiledCode(compiledCode: typed): untyped =
## Simple macro to dump the final generated source code form of the
argument
## after all nested macros have been called, template code has been
inserted, etc.
echo "\n#### final generated code:"
echo repr(compiledCode)
# Return what was passed in so that compilation can continue
result = compiledCode
Run
However, as I mentioned in the OP, the problem only occurs for a destructor
call with a `ref object` argument. It works fine if the argument is a
non-`ref`.