From 3e2852cb1b8f20ee456c9497b68bd28dc426c8ba Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 25 Sep 2025 00:40:32 +0800 Subject: [PATCH] fixes #21476; internal error: proc has no result symbol (#25192) fixes #21476 --- compiler/semstmts.nim | 9 +++++++++ tests/iter/titer14.nim | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 6c8542b584..ae4c744ead 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -2644,9 +2644,18 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, else: nil # semantic checking also needed with importc in case used in VM + + let isInlineIterator = isInlineIterator(s.typ) s.ast[bodyPos] = hloBody(c, semProcBody(c, n[bodyPos], resultType)) # unfortunately we cannot skip this step when in 'system.compiles' # context as it may even be evaluated in 'system.compiles': + + if isInlineIterator and s.typ.callConv == ccClosure: + # iterators without explicit callconvs are lifted to closure, + # we need to add a result symbol for them + maybeAddResult(c, s, n) + + trackProc(c, s, s.ast[bodyPos]) else: if (s.typ.returnType != nil and s.kind != skIterator): diff --git a/tests/iter/titer14.nim b/tests/iter/titer14.nim index 7e483bbae2..fbaf0d553f 100644 --- a/tests/iter/titer14.nim +++ b/tests/iter/titer14.nim @@ -5,3 +5,11 @@ proc f() = iterator b(): int = for x in a(): yield x + +proc y(n: ref int) = discard + +proc w(n: ref int) = + iterator a(): int = y(n) + let x = a + +w(nil)