[nim check]fix #17460 (#17569)

This commit is contained in:
flywind
2021-03-30 00:28:55 +08:00
committed by GitHub
parent 7ad49950bd
commit 3f9c51a332
2 changed files with 21 additions and 0 deletions

View File

@@ -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)

19
tests/errmsgs/t17460.nim Normal file
View File

@@ -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()