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

mutable iterator cannot yield named tuples #12945

Closed
disruptek opened this issue Dec 20, 2019 · 2 comments
Closed

mutable iterator cannot yield named tuples #12945

disruptek opened this issue Dec 20, 2019 · 2 comments
Labels

Comments

@disruptek
Copy link
Contributor

@disruptek disruptek commented Dec 20, 2019

This does not compile and I think it should.

iterator pairs*[K, V](group: Group[K, V]): (K, V) =
  for key, value in group.table.pairs:
    yield (key: key, val: value)

iterator mpairs*[K, V](group: Group[K, V]): (K, var V) =
  for key, value in group.table.mpairs:
    yield (key: key, val: value)  # compiler error
    yield (key, value)            # compiles

Nim Compiler Version 1.0.4 [Linux: amd64]
Compiled at 2019-12-16
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 97e0ce3c75c9348226ea1fcdfc601c6fbe5c0e75
active boot switches: -d:danger
@disruptek

This comment has been minimized.

Copy link
Contributor Author

@disruptek disruptek commented Dec 20, 2019

Looking at this more closely...

iterator mpairs*[K, V](group: var Group[K, V]): tuple[key: K, val: var V] =
  for key, value in group.table.mpairs:
    yield (key, value)

This syntax produces a codegen error:

/home/adavidoff/.cache/nim/nimph_r/@mnimph@sdependency.nim.c: In function ‘addedRequirements__NqsTCaB70tMWsL58CQq9czQ’:
/home/adavidoff/.cache/nim/nimph_r/@mnimph@sdependency.nim.c:3671:24: error: ‘*dependencies’ is a pointer; did you mean to use ‘->’?
     T4_ = &dependencies->Sup;
                        ^~
                        ->

This one produces a compiler error:

iterator mpairs*[K, V](group: Group[K, V]): tuple[key: K, val: var V] =
  for key, value in group.table.mpairs:
    yield (key: key, val: value)
/home/adavidoff/git/nimph/src/nimph/group.nim(129, 25) Error: expression has no address

This one compiles:

iterator mpairs*[K, V](group: Group[K, V]): tuple[key: K, val: var V] =
  for key, value in group.table.mpairs:
    yield (key, value)
@cooldome

This comment has been minimized.

Copy link
Member

@cooldome cooldome commented Dec 24, 2019

I will make a fix for no address issue

@cooldome cooldome added the Iterators label Dec 24, 2019
cooldome added a commit to cooldome/Nim that referenced this issue Dec 24, 2019
@Araq Araq closed this in 649bf32 Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.