summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2015-01-28 23:09:20 +0000
committerDominik Picheta <dominikpicheta@googlemail.com>2015-01-28 23:10:25 +0000
commit3ac2e003345878d6e6f55f9f5768e4a488acfe6e (patch)
tree20018f305e58954e68622ea84c209fa746bcd62e
parenta4b27622491c9844da2ca15bb8cc3ec36356484e (diff)
downloadNim-3ac2e003345878d6e6f55f9f5768e4a488acfe6e.tar.gz
Fixes #1642.
-rw-r--r--compiler/ccgexprs.nim8
-rw-r--r--tests/closure/tissue1642.nim6
2 files changed, 12 insertions, 2 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 98fb25899..591b6d76f 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2095,14 +2095,18 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
       # due to a bug/limitation in the lambda lifting, unused inner procs
       # are not transformed correctly. We work around this issue (#411) here
       # by ensuring it's no inner proc (owner is a module):
-      if prc.skipGenericOwner.kind == skModule:
+      #
+      # We also check whether the proc captures its environment here to
+      # prevent issue #1642.
+      if prc.skipGenericOwner.kind == skModule and
+         tfCapturesEnv in prc.typ.flags:
         if (optDeadCodeElim notin gGlobalOptions and
             sfDeadCodeElim notin getModule(prc).flags) or
             ({sfExportc, sfCompilerProc} * prc.flags == {sfExportc}) or
             (sfExportc in prc.flags and lfExportLib in prc.loc.flags) or
             (prc.kind == skMethod): 
           # we have not only the header: 
-          if prc.getBody.kind != nkEmpty or lfDynamicLib in prc.loc.flags: 
+          if prc.getBody.kind != nkEmpty or lfDynamicLib in prc.loc.flags:
             genProc(p.module, prc)
   of nkParForStmt: genParForStmt(p, n)
   of nkState: genState(p, n)
diff --git a/tests/closure/tissue1642.nim b/tests/closure/tissue1642.nim
new file mode 100644
index 000000000..d396630c8
--- /dev/null
+++ b/tests/closure/tissue1642.nim
@@ -0,0 +1,6 @@
+discard """
+  file: "tissue1642.nim"
+"""
+block:
+  var i = 0
+  proc p() = inc(i)