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

Hash.clone differs from hash assignment; the hash and its clone are spookily entangled #5175

Closed
p6rt opened this issue Mar 14, 2016 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 14, 2016

Migrated from rt.perl.org#127704 (status was 'resolved')

Searchable as RT127704$

@p6rt
Copy link
Author

p6rt commented Mar 14, 2016

From @masak

<masak> m​: my %h1; %h1<foo> = 1; my %h2 = %h1; %h2<bar> = 2; say %h1
<camelia> rakudo-moar 42fb81​: OUTPUT«foo => 1␤»
<masak> m​: my %h1; %h1<foo> = 1; my %h2 := %h1.clone; %h2<bar> = 2; say %h1
<camelia> rakudo-moar 42fb81​: OUTPUT«bar => 2, foo => 1␤»
* masak submits rakudobug
<masak> pretty sure this one is a regression. 007 has had code based
on Hash.clone for a long while to indicate "and now we enter a new
scope"
<masak> the bug manifests in the fact that old variables don't go away
when we leave a scope
<moritz> m​: my %h1; %h1<foo> = 1; my %h2 = %h1.clone; %h2<bar> = 2; say %h1
<camelia> rakudo-moar 42fb81​: OUTPUT«foo => 1␤»
<moritz> masak​: I see
<moritz> the fact that one often uses hash assignment (which copies)
seems to shadow this bug from every day observation
<masak> moritz​: reason I didn't simply use hash assignment is that in
my case, the hash was in an array.
<moritz> star-m​: my %h1; %h1<foo> = 1; my %h2 := %h1.clone; %h2<bar> =
2; say %h1
<camelia> star-m 2016.01​: OUTPUT«bar => 2, foo => 1␤»
* moritz wonders if a simple method clone in class Hash or Map helps
<moritz> m​: say Hash.^mro
<camelia> rakudo-moar 42fb81​: OUTPUT«((Hash) (Map) (Cool) (Any) (Mu))␤»

@p6rt
Copy link
Author

p6rt commented Mar 14, 2016

From @moritz

On Mon Mar 14 01​:40​:19 2016, masak wrote​:

<masak> m​: my %h1; %h1<foo> = 1; my %h2 = %h1; %h2<bar> = 2; say %h1
<camelia> rakudo-moar 42fb81​: OUTPUT«foo => 1␤»
<masak> m​: my %h1; %h1<foo> = 1; my %h2 := %h1.clone; %h2<bar> = 2; say %h1
<camelia> rakudo-moar 42fb81​: OUTPUT«bar => 2, foo => 1␤»
* masak submits rakudobug

Fixed in rakudo/rakudo@6b2b34a791, tested in Raku/roast@ab74762da1

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Mar 14, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 14, 2016

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 14, 2016
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant