fixes #21306; fixes #20485; don't transform yields in the var section when introducing new local vars [backport: 1.6] (#21489)
* fixes #21306; don't transform yields in the var section when introducing new local vars * adds `inVarSection` so the var section in the var section is freshed * use `isIntroducingNewLocalVars` to avoid yield transformations in var sections * fixes comments
This commit is contained in:
parent
0319824322
commit
f2dad94902
2 changed files with 118 additions and 1 deletions
|
|
@ -50,6 +50,7 @@ type
|
|||
module: PSym
|
||||
transCon: PTransCon # top of a TransCon stack
|
||||
inlining: int # > 0 if we are in inlining context (copy vars)
|
||||
isIntroducingNewLocalVars: bool # true if we are in `introducingNewLocalVars` (don't transform yields)
|
||||
contSyms, breakSyms: seq[PSym] # to transform 'continue' and 'break'
|
||||
deferDetected, tooEarly: bool
|
||||
graph: ModuleGraph
|
||||
|
|
@ -450,7 +451,9 @@ proc transformYield(c: PTransf, n: PNode): PNode =
|
|||
result.add(c.transCon.forLoopBody)
|
||||
else:
|
||||
# we need to introduce new local variables:
|
||||
c.isIntroducingNewLocalVars = true # don't transform yields when introducing new local vars
|
||||
result.add(introduceNewLocalVars(c, c.transCon.forLoopBody))
|
||||
c.isIntroducingNewLocalVars = false
|
||||
|
||||
for idx in 0 ..< result.len:
|
||||
var changeNode = result[idx]
|
||||
|
|
@ -1036,7 +1039,7 @@ proc transform(c: PTransf, n: PNode): PNode =
|
|||
else:
|
||||
result = transformSons(c, n)
|
||||
of nkYieldStmt:
|
||||
if c.inlining > 0:
|
||||
if c.inlining > 0 and not c.isIntroducingNewLocalVars:
|
||||
result = transformYield(c, n)
|
||||
else:
|
||||
result = transformSons(c, n)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue