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

shallowCopy in iterator yielding full copies #5887

Open
mratsim opened this issue May 25, 2017 · 3 comments
Open

shallowCopy in iterator yielding full copies #5887

mratsim opened this issue May 25, 2017 · 3 comments
Labels
stale Staled PR/issues; remove the label after fixing them

Comments

@mratsim
Copy link
Collaborator

mratsim commented May 25, 2017

Here is the test case:

iterator foo(s: seq[int]): seq[int] =
  var sha_cp: seq[int]
  shallowCopy(sha_cp, s)

  echo "\nOriginal seq repr\n" & s.repr
  echo "Copy repr inside iter\n" & s.repr

  for _ in s:
    yield sha_cp

let s = @[1, 2, 3, 4, 5]
for sequence in s.foo:
  echo "#### Yielded repr"
  echo sequence.repr

Output

Original seq repr
0x10075f048[1, 2, 3, 4, 5]

Copy repr inside iter
0x10075f048[1, 2, 3, 4, 5]

#### Yielded repr
0x10075f678[1, 2, 3, 4, 5]

#### Yielded repr
0x10075f990[1, 2, 3, 4, 5]

#### Yielded repr
0x10075fca8[1, 2, 3, 4, 5]

#### Yielded repr
0x10075ffc0[1, 2, 3, 4, 5]

#### Yielded repr
0x100769318[1, 2, 3, 4, 5]
@Araq
Copy link
Member

Araq commented May 29, 2017

The compiler is allowed to do this.

@andreaferretti
Copy link
Collaborator

Is it? What is the reason?

@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Staled PR/issues; remove the label after fixing them
Projects
None yet
Development

No branches or pull requests

3 participants