diff options
-rw-r--r-- | compiler/semstmts.nim | 3 | ||||
-rw-r--r-- | tests/errmsgs/t19224.nim | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 4f01f508e..270086e66 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -853,6 +853,9 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode = var iterAfterVarLent = iter.skipTypes({tyGenericInst, tyAlias, tyLent, tyVar}) # n.len == 3 means that there is one for loop variable # and thus no tuple unpacking: + if iterAfterVarLent.kind == tyEmpty: + localError(c.config, n[^2].info, "cannot infer element type of $1" % + renderTree(n[^2], {renderNoComments})) if iterAfterVarLent.kind != tyTuple or n.len == 3: if n.len == 3: if n[0].kind == nkVarTuple: diff --git a/tests/errmsgs/t19224.nim b/tests/errmsgs/t19224.nim new file mode 100644 index 000000000..7a9ecb2e7 --- /dev/null +++ b/tests/errmsgs/t19224.nim @@ -0,0 +1,12 @@ +discard """ +cmd: "nim check --hints:off $file" +errormsg: "" +nimout: ''' +t19224.nim(10, 10) Error: cannot infer element type of items([]) +t19224.nim(12, 10) Error: cannot infer element type of items(@[]) +''' +""" + +for _ in []: discard + +for _ in @[]: discard |