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 iteration over mutable type produces a codegen error #13510

Open
disruptek opened this issue Feb 26, 2020 · 7 comments
Open

mutable iteration over mutable type produces a codegen error #13510

disruptek opened this issue Feb 26, 2020 · 7 comments

Comments

@disruptek
Copy link
Contributor

This is a portion of #12945 that wasn't solved.

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;
                        ^~
                        ->

Tested in 1.0.6 and devel.

@krux02
Copy link
Contributor

krux02 commented Feb 26, 2020

This is not a reproducible example.

@ghost
Copy link

ghost commented Jul 25, 2020

@disruptek Can't reproduce on latest devel:

import tables
type
  Group[K, V] = object
    table: Table[K, V]

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)

var grp = Group[string, string](table: initTable[string, string]())
grp.table["hello"] = "world"
grp.table["yes"] = "no"

for (k, v) in grp.mpairs():
  v = "hi"

@ghost ghost added the Iterators label Jul 26, 2020
@disruptek
Copy link
Contributor Author

Here's my repro, which still demonstrates the problem:

https://github.com/disruptek/nimph/blob/master/src/nimph/group.nim#L131

@krux02
Copy link
Contributor

krux02 commented Aug 18, 2020

@disruptek the comment I made about not being reproducable means that the issue should contain a code listing according to the issue template that can be compiled without any further change to reproduce the problem.

@disruptek
Copy link
Contributor Author

It's a nice idea but I'm loathe to release a broken version of nimph just to satisfy the issue template. The fact that I'm currently unable to reduce the bug doesn't make the bug any less real.

@krux02
Copy link
Contributor

krux02 commented Aug 19, 2020

Well then you should at least mention in the issue that you were unable to reduce the bug to a small example. The problem here is, back when I worked on bugs I skipped issues that don't bother to put in a reproducable example. And how should I distinguish from "you tried really hard to reduce the problem but couldn't" from "You didn't bother to put in a reproducable example", if you don't explain why you couln't reduce the problem.

@disruptek
Copy link
Contributor Author

If I knew why I couldn’t reduce the bug then we wouldn’t be having this conversation.

If you want to help without working on this vague bug, I’m working on a tool to reduce bugs. It’s very crude and has grown less ambitious as I’ve run up against problems in the compiler, but it’s arguably a better place to type than GitHub comments:

https://github.com/disruptek/dust

It doesn’t yet attempt to reduce backend bugs such as this one. Maybe that would make a good first PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants