Skip Menu |
Report information
Id: 128948
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: zefram [at] fysh.org
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: Zefram <zefram [...] fysh.org>
Date: Mon, 15 Aug 2016 14:56:30 +0100
To: rakudobug [...] perl.org
Subject: [BUG] Pair.WHICH distinguishes pairs with same container value
Download (untitled) / with headers
text/plain 890b
Pair.WHICH has special behaviour if the pair's value is a container: Show quoted text
> my $a; my $b = :a($a); my $c = :a($a); $a = 3; for $b, $c { say (.WHICH, .perl) }
(Pair|47082244733376 :a(3)) (Pair|47082244733472 :a(3)) As you can see, both pairs are behaviourally equivalent, in that they have the same key and refer to the same value container, thus both seeing the change in the value contained in it. But they get different .WHICH values, falsely suggesting that they're distinct. (=== follows .WHICH in falsely indicating that they're distinct.) The container case of .WHICH is using the default .WHICH that reflects the physical identity of the Pair objects. To get the intended equivalence, Pair.WHICH needs to reflect the key and the identity of the container held in the value slot. I think that just removing the branch of Pair.WHICH for the container case would be correct. -zefram
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
CC: bugs-bitbucket [...] rt.perl.org
Date: Mon, 15 Aug 2016 16:01:58 +0200
Subject: Re: [perl #128948] [BUG] Pair.WHICH distinguishes pairs with same container value
To: "Zefram (via RT)" <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 1.6k
A Pair in which the value is a container, is mutable. And therefore cannot be a value type: $ 6 'my $p = a => my $ = 42; say $p.WHICH; $p.value = 666; say $p.WHICH' Pair|140196969054016 Pair|140196969054016 Note if the value is *not* a container: $ 6 'my $p = a => 42; say $p.WHICH; $p.value = 666; say $p.WHICH' Pair|Str|a|Int|42 Cannot modify an immutable Int in block <unit> at -e line 1 I think this is ENOTABUG Show quoted text
> On 15 Aug 2016, at 15:56, Zefram (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Zefram > # Please include the string: [perl #128948] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=128948 > > > > Pair.WHICH has special behaviour if the pair's value is a container: >
>> my $a; my $b = :a($a); my $c = :a($a); $a = 3; for $b, $c { say (.WHICH, .perl) }
> (Pair|47082244733376 :a(3)) > (Pair|47082244733472 :a(3)) > > As you can see, both pairs are behaviourally equivalent, in that they > have the same key and refer to the same value container, thus both seeing > the change in the value contained in it. But they get different .WHICH > values, falsely suggesting that they're distinct. (=== follows .WHICH > in falsely indicating that they're distinct.) > > The container case of .WHICH is using the default .WHICH that reflects the > physical identity of the Pair objects. To get the intended equivalence, > Pair.WHICH needs to reflect the key and the identity of the container held > in the value slot. I think that just removing the branch of Pair.WHICH > for the container case would be correct. > > -zefram
Date: Mon, 15 Aug 2016 15:12:37 +0100
From: Zefram <zefram [...] fysh.org>
To: Elizabeth Mattijsen via RT <perl6-bugs-followup [...] perl.org>
Subject: Re: [perl #128948] [BUG] Pair.WHICH distinguishes pairs with same container value
Download (untitled) / with headers
text/plain 604b
Elizabeth Mattijsen via RT wrote: Show quoted text
>A Pair in which the value is a container, is mutable.
Not really. The *container* is mutable. The Pair can't be changed to refer to any other container, as far as I can see: Show quoted text
> my $a; my $b = :a($a); my $c = :a($a); $b.value = 3; $b.perl, $c.perl
(:a(3) :a(3)) I've mutated something there, but it's not one of the pairs to the exclusion of the other. It's the thing they share, the value container. These pairs should therefore show the same identity under .WHICH. I'd expect the .WHICH string to be something like "Pair|Str|a|Scalar|47608575457088". -zefram
From: Zefram <zefram [...] fysh.org>
Date: Tue, 16 Aug 2016 17:33:13 +0100
Subject: Re: [perl #128948] [BUG] Pair.WHICH distinguishes pairs with same container value
To: Elizabeth Mattijsen via RT <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 637b
I wrote: Show quoted text
> I'd expect the .WHICH string to be something like >"Pair|Str|a|Scalar|47608575457088".
Upon further investigation, I think this requires multi method WHICH(Pair:D:) { "Pair|" ~ $!key.WHICH ~ "|" ~ $!value.VAR.WHICH } That is, .VAR needs to be applied to $!value, which isn't currently in the WHICH method. My original suggestion of merely using the existing non-container branch of the WHICH method, without this fix, would cause the WHICH to reflect the identity of the value in the container. That outcome is what Liz then pointed out would be incorrect, though it was never what I intended. -zefram


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org