Skip to content

Move analysis missing in closure iterator #25333

@arnetheduck

Description

@arnetheduck

Nim Version

2.2.4, 86bbc73

Description

In ORC, the following snippet does not compile, though it should.

In refc, the snippet does compile but copies NoCopy even though it should move it. In fact, 5 (!) copies of "test" happen on its journey to the echo.

type NoCopy = object
  v: string
proc `=copy`(a: var NoCopy, b: NoCopy) {.error.}

proc sinkMe(v: sink NoCopy) =
  echo v.v

proc iter(v: sink NoCopy): iterator(): int =
  iterator(): int =
    yield 1
    sinkMe(v)

proc main() =
  let vvv = iter(NoCopy(v: "test"))
  for i in vvv():
    echo i

main()

Current Output

testit.nim(13, 12) Error: '=dup' is not available for type <sink NoCopy>, which is inferred from unavailable '=copy'; requires a copy because it's not the last read of ':envP.`:up`.v0'; routine: :anonymous

Expected Output


Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions