From 89781124579fdf7fe884aca093ed9348195a57af Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 14 Oct 2020 13:58:36 +0200 Subject: [PATCH] fixes a C code generator regression, no need to backport, only the 1.4 line is affected (#15569) --- compiler/ccgcalls.nim | 2 +- tests/ccgbugs/t2procs.nim | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/ccgbugs/t2procs.nim diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 6c5b721c70..242e9f5cf4 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -249,7 +249,7 @@ proc openArrayLoc(p: BProc, formalType: PType, n: PNode): Rope = else: internalError(p.config, "openArrayLoc: " & typeToString(a.t)) proc withTmpIfNeeded(p: BProc, a: TLoc, needsTmp: bool): TLoc = - if needsTmp: + if needsTmp and a.lode.typ != nil: var tmp: TLoc getTemp(p, a.lode.typ, tmp, needsInit=false) genAssignment(p, tmp, a, {}) diff --git a/tests/ccgbugs/t2procs.nim b/tests/ccgbugs/t2procs.nim new file mode 100644 index 0000000000..d8b7a2815a --- /dev/null +++ b/tests/ccgbugs/t2procs.nim @@ -0,0 +1,18 @@ +discard """ + output: '''before +1 +before +2''' +""" + +proc fn[T1, T2](a: T1, b: T2) = + a(1) + b(2) + +fn( (proc(x: int) = + echo "before" # example block, can span multiple lines + echo x), + (proc (y: int) = + echo "before" + echo y) +)