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
This commit is contained in:
Jake Leahy
2026-04-05 22:00:04 +10:00
committed by GitHub
parent 0028ea563c
commit f9524861f3
2 changed files with 14 additions and 1 deletions

View File

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

13
tests/iter/t25704.nim Normal file
View File

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