From f9524861f3de359a2248935231da37fff636a45c Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Sun, 5 Apr 2026 22:00:04 +1000 Subject: [PATCH] Fix generic tuple unpacking in iterators (#25705) Fixes #25704 This makes sure that `iter` still has `tyGenericInst` skipped like before, without skipping it for `iterType` which requires it --- compiler/semstmts.nim | 2 +- tests/iter/t25704.nim | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/iter/t25704.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 398707bd12..5a04b2b592 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1101,7 +1101,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode = iterBase.skipModifier else: skipTypes(iterBase, {tyAlias, tySink, tyOwned}) - var iter = iterType + var iter = skipTypes(iterType, {tyGenericInst}) var iterAfterVarLent = iter.skipTypes({tyGenericInst, tyAlias, tyLent, tyVar}) # n.len == 3 means that there is one for loop variable # and thus no tuple unpacking: diff --git a/tests/iter/t25704.nim b/tests/iter/t25704.nim new file mode 100644 index 0000000000..bab4716c35 --- /dev/null +++ b/tests/iter/t25704.nim @@ -0,0 +1,13 @@ +import std/[sugar, strutils] + +type Res[T] = tuple[a: int, b: string] +iterator test(): Res[string] = + yield (1, "") + +for (i, s) in test(): + static: + echo typeof(i) + echo typeof(s) + let + a: int = i + b: string = s