Skip to content

Broken overload resolution between proc and iterator for iterable #22098

@ZoomRmc

Description

@ZoomRmc

Description

The following code compiles and runs fine unless the proc is uncommented. If it is, the error is: Error: undeclared identifier: 'it'. Until the RFC#397 is implemented, the proc shouldn't even affect this code, because currently it works only when the resulting seq is followed by implicit items.

from std/sequtils import toSeq
template moopIt[T](iter: iterable[T]; expr: untyped): untyped =
  iterator internal(): auto {.gensym.} =
    for it {.inject.} in iter:
      yield expr
  internal()

iterator splat(s: string): string = (for i in @["X", "Y", "Z"]: yield i)
#proc splat(s: string): seq[string] = @["A", "B", "C"]

assert splat("").moopIt(it[0]).toSeq() == @['X', 'Y', 'Z']

Nim Version

Nim Compiler Version 1.9.3 [Linux: amd64]
Compiled at 2023-06-14
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 20dfdba
active boot switches: -d:release

Current Output

No response

Expected Output

* proc doesn't affect resolution, as it doesn't fit itself
* iterator given precedence when resolving `iterable`

Possible Solution

No response

Additional Information

Possibly relevant:
#19206

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