Skip to content

Illegal capture of closure iterator, when should be legal #20152

@yglukhov

Description

@yglukhov
proc foo() =
  iterator it() {.closure.} =
    discard
  proc useIter() {.nimcall.} =
    var iii = it # <-- illegal capture
  useIter()
foo()
nim c test
.../test.nim(5, 15) Error: illegal capture 'it' because 'useIter' has the calling convention: <nimcall>

This capture should be legal as it is a fresh local instance of the iterator.

nim --version
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-08-03
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 0d734d7966644018207a20cf23f16912f9c276d8
active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions