From 3b80b24e40e649917052e6c1730395b3c3e180ea Mon Sep 17 00:00:00 2001 From: Saem Ghani Date: Thu, 11 May 2023 11:31:46 -0700 Subject: [PATCH] lambdalifting: ignore AST literals for var capture (#697) ## Summary `nkNimNodeLit` are no longer scanned during var capture detection, ensuring that literals do not alter capture analysis of a routine holding typed literal AST with symbols from the outer routine. ## Details Capture detection is done in two modules `lambdalifting` and `sempass2` in the `detectCapturedVars` and `detectCapture` procedures, respectively. With this change both procedures do not traverse into `nkNimNodeLit` (treating them as more opaque literal data) for literal analysis. A regression tests has been added a test for this (thanks to Zerbina). --------- Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/sem/lambdalifting.nim | 2 ++ compiler/sem/sempass2.nim | 2 ++ tests/lang_callable/macros/tnodeliteral.nim | 29 +++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/lang_callable/macros/tnodeliteral.nim diff --git a/compiler/sem/lambdalifting.nim b/compiler/sem/lambdalifting.nim index 780b99972b8..669c8d23cf7 100644 --- a/compiler/sem/lambdalifting.nim +++ b/compiler/sem/lambdalifting.nim @@ -494,6 +494,8 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = detectCapturedVars(n[namePos], owner, c) of nkReturnStmt: detectCapturedVars(n[0], owner, c) + of nkNimNodeLit: + discard "skip node literals as they're data not code" else: for i in 0..