From 87511babb561315b2e650909ec782ce4704a4c1b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 8 Sep 2026 04:23:43 +0800 Subject: [PATCH] =?UTF-8?q?fixes=20#26176;=20nim=20js:=20explicit=20{.clos?= =?UTF-8?q?ure.}=20on=20a=20lambda=20with=20parameter=E2=80=A6=20(#26179)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …s crashes codegen fixes #26176 It follows the same method of the C backend. Don't insert "this" in JavaScript backend If no variables are captured by closure functions. --- compiler/jsgen.nim | 2 +- tests/js/tclosures.nim | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index a0134acbe9..3d32e7d60f 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1220,7 +1220,7 @@ proc generateHeader(p: PProc, prc: PSym): Rope = result = "" let typ = prc.typ if jsNoLambdaLifting notin p.config.legacyFeatures: - if typ.callConv == ccClosure: + if typ.callConv == ccClosure and tfCapturesEnv in typ.flags: # we treat Env as the `this` parameter of the function # to keep it simple let env = prc.ast[paramsPos].lastSon diff --git a/tests/js/tclosures.nim b/tests/js/tclosures.nim index 4f1c28de3f..ee3a35cb61 100644 --- a/tests/js/tclosures.nim +++ b/tests/js/tclosures.nim @@ -50,6 +50,11 @@ let results = runCallbacks() doAssert(expected == $results) +block issue26176: + let g = proc(x: int): int {.closure.} = + result = x + 1 + doAssert g(1) == 2 + block issue7048: block: proc foo(x: seq[int]): auto =