Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong error for iterators with no body and pragma macro #24440

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]