From e42c304e4ae623ea8dea9594b531f119bb4142e9 Mon Sep 17 00:00:00 2001 From: nc-x Date: Sun, 5 May 2019 15:52:41 +0530 Subject: [PATCH] Fix loop tuple unpacking in templates (#11174) * Fix loop tuple unpacking in templates * Add test --- compiler/semtempl.nim | 6 +++++- tests/tuples/tfortupleunpack.nim | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 2854c90ae9..3f647cdc12 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -372,7 +372,11 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = openScope(c) n.sons[L-2] = semTemplBody(c, n.sons[L-2]) for i in countup(0, L - 3): - addLocalDecl(c, n.sons[i], skForVar) + if n[i].kind == nkVarTuple: + for j in 0 ..< sonsLen(n[i])-1: + addLocalDecl(c, n[i][j], skForVar) + else: + addLocalDecl(c, n.sons[i], skForVar) openScope(c) n.sons[L-1] = semTemplBody(c, n.sons[L-1]) closeScope(c) diff --git a/tests/tuples/tfortupleunpack.nim b/tests/tuples/tfortupleunpack.nim index 9aeb7c5d62..e222a1ae67 100644 --- a/tests/tuples/tfortupleunpack.nim +++ b/tests/tuples/tfortupleunpack.nim @@ -9,6 +9,7 @@ output: ''' @[(88, 99, 11), (88, 99, 11)] @[(7, 6, -28), (7, 6, -28)] 12 +110100 ''' """ @@ -41,3 +42,11 @@ proc test[n]() = for (a,b) in @[(1,2)]: echo a,b test[string]() + +iterator tuples: (int, (int, int)) = yield (1,(10, 100)) + +template t11164 = + for i, (a, b) in tuples(): + echo i, a , b + +t11164()