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 =