Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimsuggest: def result is incorrect when using the for loop without explicit call of .items or .pairs. #24487

Open
doongjohn opened this issue Dec 1, 2024 · 0 comments

Comments

@doongjohn
Copy link

Description

def result is incorrect when using the for loop without explicit call of .items or .pairs.

import std/tables

let t = initTable[string, int]()
for key, value in t:
  discard value

let r = 0 .. 2
for value in r:
  discard value

let s = @[1, 2, 3]
for value in s:
  discard value

let str = "hello"
for value in str:
  discard value

Nim Version

Nim Compiler Version 2.2.1 [Windows: amd64]
Compiled at 2024-11-28
Copyright (c) 2006-2024 by Andreas Rumpf

active boot switches: -d:release

Current Output

for key, value in t:
                  ^ <-- here
> def 4:19
def     skIterator      tables.pairs    iterator (t: Table[pairs.A, pairs.B]): (A, B){.inline.} ...\nim\lib\pure\collections\tables.nim      680     9       "Iterates over any `(key, value)` pair in the table `t`.\x0A\x0ASee also:\x0A* `mpairs iterator<#mpairs.i,Table[A,B]>`_\x0A* `keys iterator<#keys.i,Table[A,B]>`_\x0A* `values iterator<#values.i,Table[A,B]>`_\x0A\x0A**Examples:**\x0A\x0A  \x0A  let a = {\x0A    \'o\': [1, 5, 7, 9],\x0A    \'e\': [2, 4, 6, 8]\x0A    }.toTable\x0A\x0A  for k, v in a.pairs:\x0A    echo \"key: \", k\x0A    echo \"value: \", v\x0A\x0A  # key: e\x0A  # value: [2, 4, 6, 8]\x0A  # key: o\x0A  # value: [1, 5, 7, 9]\x0A  "  100

for value in r:
             ^ <-- here
> def 8:14
def     skIterator      iterators.items iterator (s: Slice[items.T]): T: Ordinal{.inline.}      ...\nim\lib\system\iterators.nim    140      9       "Iterates over the slice `s`, yielding each value between `s.a` and `s.b`\x0A(inclusively)."    100

for value in s:
             ^ <-- here
> def 12:14
def     skIterator      iterators.items iterator (a: seq[T]): lent T{.inline, raises: <inferred> [].}   ...\nim\lib\system\iterators.nim     247     9       "Iterates over each item of `a`."       100

for value in str:
             ^ <-- here
> def 16:14
def     skIterator      iterators.items iterator (a: string): char{.inline, noSideEffect, gcsafe, raises: <inferred> [].}       ...\nim\lib\system\iterators.nim     265     9       "Iterates over each item of `a`."

Expected Output

for key, value in t:
                  ^ <-- here
> def 4:19
def     skLet   main.t  Table[system.string, system.int]        ...\main.nim        3       4       ""

for value in r:
             ^ <-- here
> def 8:14
def     skLet   main.r  HSlice[system.int, system.int]  ...\main.nim        7       4       ""

for value in s:
             ^ <-- here
> def 12:14
def     skLet   main.s  seq[int]        ...\main.nim        11      4       ""

for value in str:
             ^ <-- here
> def 16:14
def     skLet   main.str        string  ...\main.nim        15      4       ""

Known Workarounds

No response

Additional Information

table and string works as expected in nimsuggest --v2 but not in v3, v4

for key, value in t:
                  ^ <-- here

for value in str:
             ^ <-- here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant