mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-17 02:32:11 +00:00
…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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user