summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2021-03-30 00:28:55 +0800
committerGitHub <noreply@github.com>2021-03-29 09:28:55 -0700
commit3f9c51a332dc798e1f4d61480ca8b6048ab281cd (patch)
tree4beebafcb286f98fd2456a8defc4af2b7bb61874
parent7ad49950bd5ec05f145dc43ae35f51127ea76366 (diff)
downloadNim-3f9c51a332dc798e1f4d61480ca8b6048ab281cd.tar.gz
[nim check]fix #17460 (#17569)
-rw-r--r--compiler/semstmts.nim2
-rw-r--r--tests/errmsgs/t17460.nim19
2 files changed, 21 insertions, 0 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index fee43162e..bbfd49e2a 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -726,6 +726,8 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
       if n[0].kind == nkVarTuple:
         if n[0].len-1 != iterAfterVarLent.len:
           localError(c.config, n[0].info, errWrongNumberOfVariables)
+          return errorNode(c, n)
+
         for i in 0..<n[0].len-1:
           var v = symForVar(c, n[0][i])
           if getCurrOwner(c).kind == skModule: incl(v.flags, sfGlobal)
diff --git a/tests/errmsgs/t17460.nim b/tests/errmsgs/t17460.nim
new file mode 100644
index 000000000..8192cc4c8
--- /dev/null
+++ b/tests/errmsgs/t17460.nim
@@ -0,0 +1,19 @@
+discard """
+  cmd: "nim check $options $file"
+  errormsg: "wrong number of variables"
+"""
+
+iterator xclusters*[T](a: openarray[T]; s: static[int]): array[s, T] {.inline.} =
+  var result: array[s, T] # iterators have no default result variable
+  var i = 0
+  while i < len(a):
+    for j, x in mpairs(result):
+      x = a[(i + j) mod len(a)]
+    yield result
+    inc(i)
+
+proc m =
+  for (i, j, k) in xclusters([1, 2, 3, 4, 5], 3):
+    echo i, j, k
+
+m()
\ No newline at end of file