nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

Don't lift variables that don't see a return or yield (wip) #23719

Open SirOlaf opened 2 weeks ago

SirOlaf commented 2 weeks ago

Snippet that inspired this, ran into issues with async code and reduced to snippet.

type Foo = object

proc `=copy`(a: var Foo, b: Foo) {.error.}

proc consumer(x: sink Foo) = discard

iterator iter(): int {.closure.} =
  var foo = Foo()
  consumer(foo)

for x in iter():
  discard