Skip Menu |
Report information
Id: 126984
Status: resolved
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

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



Subject: [BUG] WhateverCode in given doesn't get refreshed when entering surrounding block in Rakudo
Date: Mon, 21 Dec 2015 22:33:29 +0100
From: Carl Mäsak <cmasak [...] gmail.com>
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 936b
<masak> m: sub foo($x) { say (* == $x)($_) given $x }; foo(1); foo(2) <camelia> rakudo-moar cfb1f3: OUTPUT«True␤False␤» * masak submits rakudobug Examining the expression printed, it basically says "$x should be numerically equal to itself" in a circuitous way. Since this is true for any integer, I'd expect the program to print "True\nTrue\n". Here's what's wrong: <masak> m: sub foo($x) { say (* ~ $x)($_) given $x }; foo(1); foo(2) <camelia> rakudo-moar cfb1f3: OUTPUT«11␤21␤» That "1" there in "21" is from the first call to &foo -- it shouldn't be there any more. But something in the WhateverCode (* ~ $x) holds onto the old $x. <masak> this bug brought to you by: Refactoring™ <lucasb> so... the WhateverCode is caching the first value it's *created* with? <masak> yes, but only if it's in a given <masak> m: sub foo($x) { say (* ~ $x)($x) }; foo(1); foo(2) <camelia> rakudo-moar cfb1f3: OUTPUT«11␤22␤»
On Mon, 21 Dec 2015 13:33:51 -0800, masak wrote: Show quoted text
> <masak> m: sub foo($x) { say (* == $x)($_) given $x }; foo(1); foo(2) > <camelia> rakudo-moar cfb1f3: OUTPUT«True␤False␤» > * masak submits rakudobug > > Examining the expression printed, it basically says "$x should be > numerically equal to itself" in a circuitous way. Since this is true > for any integer, I'd expect the program to print "True\nTrue\n". > > Here's what's wrong: > > <masak> m: sub foo($x) { say (* ~ $x)($_) given $x }; foo(1); foo(2) > <camelia> rakudo-moar cfb1f3: OUTPUT«11␤21␤» > > That "1" there in "21" is from the first call to &foo -- it shouldn't > be there any more. But something in the WhateverCode (* ~ $x) holds > onto the old $x. > > <masak> this bug brought to you by: Refactoring™ > <lucasb> so... the WhateverCode is caching the first value it's > *created* with? > <masak> yes, but only if it's in a given > <masak> m: sub foo($x) { say (* ~ $x)($x) }; foo(1); foo(2) > <camelia> rakudo-moar cfb1f3: OUTPUT«11␤22␤»
Fudged tests preemptively added to S02-types/whatever.t in roast commit 4b2fef409.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.1k
On Mon, 21 Dec 2015 13:33:51 -0800, masak wrote: Show quoted text
> <masak> m: sub foo($x) { say (* == $x)($_) given $x }; foo(1); foo(2) > <camelia> rakudo-moar cfb1f3: OUTPUT«True␤False␤» > * masak submits rakudobug > > Examining the expression printed, it basically says "$x should be > numerically equal to itself" in a circuitous way. Since this is true > for any integer, I'd expect the program to print "True\nTrue\n". > > Here's what's wrong: > > <masak> m: sub foo($x) { say (* ~ $x)($_) given $x }; foo(1); foo(2) > <camelia> rakudo-moar cfb1f3: OUTPUT«11␤21␤» > > That "1" there in "21" is from the first call to &foo -- it shouldn't > be there any more. But something in the WhateverCode (* ~ $x) holds > onto the old $x. > > <masak> this bug brought to you by: Refactoring™ > <lucasb> so... the WhateverCode is caching the first value it's > *created* with? > <masak> yes, but only if it's in a given > <masak> m: sub foo($x) { say (* ~ $x)($x) }; foo(1); foo(2) > <camelia> rakudo-moar cfb1f3: OUTPUT«11␤22␤»
Thank you for the report. This is now fixed. Fix: https://github.com/rakudo/rakudo/commit/1ee89b54074e80c Test: https://github.com/perl6/roast/commit/2f2998733a2d8132c


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