From d4e0bca3f7f7abe714edabe37b7db8faeb0a4ebe Mon Sep 17 00:00:00 2001 From: zerbina <100542850+zerbina@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:58:40 +0000 Subject: [PATCH] tests: add a test case to `tclosure` --- tests/lang_callable/closure/tclosure.nim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/lang_callable/closure/tclosure.nim b/tests/lang_callable/closure/tclosure.nim index 005de5a0037..5c12759c05b 100644 --- a/tests/lang_callable/closure/tclosure.nim +++ b/tests/lang_callable/closure/tclosure.nim @@ -457,6 +457,24 @@ block close_over_compile_time_loc: static: p() +block close_over_compile_time_loc_2: + # nested non-compile-time-only procedures can close over locals of compile- + # time-only procedures + proc p() {.compileTime.} = + var x = 0 + proc inner(cmp: int) = # `inner` is explicitly not compile-time-only + proc innerInner(cmp: int) = + inc x + doAssert x == cmp + + innerInner(cmp) + + inner(1) + inner(2) + + static: + p() + template test(body: untyped) {.dirty.} = ## Tests that `body` works when placed in: ## - a normal procedure