Skip to content

Commit

Permalink
fix wrong error for iterators with no body and pragma macro (#24440)
Browse files Browse the repository at this point in the history
fixes #16413

`semIterator` checks if the original iterator passed to it has no body,
but it should check the processed node created by `semProcAux`.
  • Loading branch information
metagn authored Nov 15, 2024
1 parent cd9ce37 commit e239968
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2648,7 +2648,7 @@ proc semIterator(c: PContext, n: PNode): PNode =
incl(s.typ.flags, tfCapturesEnv)
else:
s.typ.callConv = ccInline
if n[bodyPos].kind == nkEmpty and s.magic == mNone and c.inConceptDecl == 0:
if result[bodyPos].kind == nkEmpty and s.magic == mNone and c.inConceptDecl == 0:
localError(c.config, n.info, errImplOfXexpected % s.name.s)
if optOwnedRefs in c.config.globalOptions and result.typ != nil:
result.typ() = makeVarType(c, result.typ, tyOwned)
Expand Down
17 changes: 17 additions & 0 deletions tests/pragmas/titeratormacro.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# issue #16413

import std/macros

macro identity(x: untyped) =
result = x.copy()
result[6] = quote do:
yield 1
discard result.toStrLit

iterator demo(): int {.identity.}
iterator demo2(): int {.identity.} = discard # but this works as expected

var s: seq[int] = @[]
for e in demo():
s.add(e)
doAssert s == @[1]

0 comments on commit e239968

Please sign in to comment.