From eda7db13d8980618bddcaaa17b81f8b804106053 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 13 Jan 2024 21:09:34 +0800 Subject: [PATCH] fixes #23180; fixes #19805; prohibits invalid tuple unpacking code in for loop (#23185) fixes #23180 fixes #19805 (cherry picked from commit ab4278d2179639f19967431a7aa1be858046f7a7) --- compiler/semstmts.nim | 5 ++++- tests/errmsgs/t17460.nim | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 06761e00c06d4..90ba4b58430e3 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -921,7 +921,10 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode = if iterAfterVarLent.kind != tyTuple or n.len == 3: if n.len == 3: if n[0].kind == nkVarTuple: - if n[0].len-1 != iterAfterVarLent.len: + if iterAfterVarLent.kind != tyTuple: + return localErrorNode(c, n, n[0].info, errTupleUnpackingTupleExpected % + [typeToString(n[1].typ, preferDesc)]) + elif n[0].len-1 != iterAfterVarLent.len: return localErrorNode(c, n, n[0].info, errWrongNumberOfVariables) for i in 0..