summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-10-03 00:00:19 +0200
committerAraq <rumpf_a@web.de>2018-10-03 00:00:19 +0200
commitc92fdb24c8bf78846d26d5488c9e33656ff93e34 (patch)
tree32d777aa7c6cfbfc21e8de1a2e46df9ec382d6a5
parentbf8595580227ece7cd8a28365d2147229acff4b9 (diff)
downloadNim-c92fdb24c8bf78846d26d5488c9e33656ff93e34.tar.gz
fixes #5015
-rw-r--r--compiler/ccgexprs.nim6
-rw-r--r--tests/closure/tclosure.nim19
2 files changed, 22 insertions, 3 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 2add4a162..b9a2a052e 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2079,7 +2079,7 @@ proc isConstClosure(n: PNode): bool {.inline.} =
       n.sons[1].kind == nkNilLit
 
 proc genClosure(p: BProc, n: PNode, d: var TLoc) =
-  assert n.kind == nkClosure
+  assert n.kind in {nkPar, nkTupleConstr, nkClosure}
 
   if isConstClosure(n):
     inc(p.module.labels)
@@ -2337,7 +2337,9 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
     else:
       genArrayConstr(p, n, d)
   of nkPar, nkTupleConstr:
-    if isDeepConstExpr(n) and n.len != 0:
+    if n.typ != nil and n.typ.kind == tyProc and n.len == 2:
+      genClosure(p, n, d)
+    elif isDeepConstExpr(n) and n.len != 0:
       exprComplexConst(p, n, d)
     else:
       genTupleConstr(p, n, d)
diff --git a/tests/closure/tclosure.nim b/tests/closure/tclosure.nim
index 09d48436e..f4364c24a 100644
--- a/tests/closure/tclosure.nim
+++ b/tests/closure/tclosure.nim
@@ -1,6 +1,6 @@
 discard """
   file: "tclosure.nim"
-  output: "1 3 6 11 20"
+  output: '''1 3 6 11 20 foo'''
 """
 # Test the closure implementation
 
@@ -45,3 +45,20 @@ proc getInterf(): ITest =
   return (setter: proc (x: int) = shared = x,
           getter: proc (): int = return shared)
 
+
+# bug #5015
+
+type Mutator* = proc(matched: string): string {.noSideEffect, gcsafe, locks: 0.}
+
+proc putMutated*(
+    MutatorCount: static[int],
+    mTable: static[array[MutatorCount, Mutator]], input: string) =
+  for i in 0..<MutatorCount: echo mTable[i](input)
+
+proc mutator0(matched: string): string =
+    "foo"
+
+const
+  mTable = [Mutator(mutator0)]
+
+putMutated(1, mTable, "foo")