Skip to content

Compiler Generates Broken Code for Anonymous Iterators #683

@Varriount

Description

@Varriount

Erroneous code is generated for generic, anonymous iterators:

proc count*[T](start: T, step = 1): auto =
  iterator counter: T {.closure.} =
    ## An iterator function that returns evenly spaced values of ordinal T,
    ## starting with `start`
    ## Note, this doesn't have any protections against overflow errors!
    ##
    ## Parameters:
    ##   start: A starting ordinal
    ##   step: The space between returned values.
    var i = start
    if step < 0:
      while True:
        dec(i, step)
        yield i
    if step > 0:
      while True:
        inc(i, step)
        yield i

  return counter

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