From 440ed8eb68e3b602f6330d7aa54cff4447d0f0bf Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 9 Aug 2016 14:16:13 +0200 Subject: [PATCH] fixes #4551 --- compiler/ccgexprs.nim | 3 +++ tests/ccgbugs/tcapture_static.nim | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/ccgbugs/tcapture_static.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index f4068b2a27..7a60e1ef7a 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1980,6 +1980,9 @@ proc exprComplexConst(p: BProc, n: PNode, d: var TLoc) = fillLoc(d, locData, t, tmp, OnStatic) else: putDataIntoDest(p, d, t, tmp) + # This fixes bug #4551, but we really need better dataflow + # analysis to make this 100% safe. + d.s = OnStatic proc expr(p: BProc, n: PNode, d: var TLoc) = case n.kind diff --git a/tests/ccgbugs/tcapture_static.nim b/tests/ccgbugs/tcapture_static.nim new file mode 100644 index 0000000000..2afb8de471 --- /dev/null +++ b/tests/ccgbugs/tcapture_static.nim @@ -0,0 +1,13 @@ +discard """ + output: '''hi''' +""" + +# bug #4551 + +proc foo() = + let arr = ["hi"] + for i, v in arr: + let bar = proc = + echo v + bar() +foo()