diff --git a/compiler/transf.nim b/compiler/transf.nim index 124ffa2f78..049ed4fa5b 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -1190,6 +1190,13 @@ proc transform(c: PTransf, n: PNode, noConstFold = false): PNode = # no need to transform type sections: return n of nkVarSection, nkLetSection: + # NIF loads let/var sections with bare nkSym children instead of nkIdentDefs. + # Expand them so transformSons reaches the value expression (e.g. for-loop). + for i in 0 ..< n.len: + if n[i].kind == nkSym: + let impl = n[i].sym.ast # triggers lazy load if Partial + if impl != nil and impl.kind == nkIdentDefs: + n[i] = impl if c.inlining > 0: # we need to copy the variables for multiple yield statements: result = transformVarSection(c, n) diff --git a/tests/ic/tmiscs.nim b/tests/ic/tmiscs.nim index 34cd79fe99..403faf360b 100644 --- a/tests/ic/tmiscs.nim +++ b/tests/ic/tmiscs.nim @@ -6,6 +6,7 @@ discard """ 2 1.0 2.0 +55 ''' """ @@ -67,3 +68,14 @@ m[0, 0] = 1.0 m[1, 1] = 2.0 echo m[0, 0] echo m[1, 1] + +template compute(body: untyped): int = + block: + body +let x = compute: + var sum = 0 + for i in 1..10: sum += i + sum + +echo x +