Nim Version
Nim Compiler Version 2.3.1 [MacOSX: arm64]
Compiled at 2026-07-16
Copyright (c) 2006-2026 by Andreas Rumpf
git hash: a6fa322
active boot switches: -d:release
Description
import std/sugar
proc foo(a: int) =
echo "Test"
proc outer() =
let a = 5
proc test(p: proc() = () => foo(a)) =
p()
This example fails specifically when there is a capture from the enclosing proc.
Current Output
vic@Mac ircdv2 % nim c test.nim
Hint: used config file '/Users/vic/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/Users/vic/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
Hint: used config file '/Users/vic/Documents/Programming/ircdv2/config.nims' [Conf]
..........................................................................SIGSEGV: Illegal storage access. (Attempt to read from nil?)
zsh: segmentation fault nim c test.nim
Expected Output
Known Workarounds
It is possible to turn the lambda expression into a nested proc, that seems to work fine:
proc foo(a: int) =
echo "Test"
proc outer() =
let a = 5
proc default() = foo(a)
proc test(p: proc() = default) =
p()
Additional Information
No response
Nim Version
Nim Compiler Version 2.3.1 [MacOSX: arm64]
Compiled at 2026-07-16
Copyright (c) 2006-2026 by Andreas Rumpf
git hash: a6fa322
active boot switches: -d:release
Description
This example fails specifically when there is a capture from the enclosing proc.
Current Output
Expected Output
Known Workarounds
It is possible to turn the lambda expression into a nested proc, that seems to work fine:
Additional Information
No response