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.57k stars 1.47k forks source link

Weird interaction between `auto` type, template and closure iterators #11421

Open dawkot opened 5 years ago

dawkot commented 5 years ago

(tried in version 0.20)

proc foo: iterator =
  template x = echo y # undeclared identifier error
  return iterator =
    let y = "foo"
    x

proc bar: auto =
  template x = echo y # no error
  return iterator =
    let y = "bar"
    x

discard foo()
discard bar()
metagn commented 3 years ago

Is this really a bug? Works with mixin y, as far as I can tell auto is just delaying semantic checking of x. There's really no guideline on when mixin has to be used and when it shouldn't.