diff options
author | Bung <crc32@qq.com> | 2022-10-02 05:19:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-01 23:19:07 +0200 |
commit | 567c3f055ded0d81d15d6d5bc18377ca8c607c6d (patch) | |
tree | 7a83240e9f6b0d76174a5d0bf3ea54ec7fd586e3 | |
parent | 0b1650576c6102ce85b4b2c0788b3a5b77154e43 (diff) | |
download | Nim-567c3f055ded0d81d15d6d5bc18377ca8c607c6d.tar.gz |
Fix #19224 For loops over a hardcoded empty array crash the compiler (#20476)
* Fix #11684 For loops over a hardcoded empty array crash the compiler * Update t19224.nim
-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 |