[perl #126984] [BUG] WhateverCode in given doesn't get refreshed when entering surrounding block in Rakudo

[email protected] ("Zoffix Znet via RT")
Newsgroups perl.perl6.compiler
Message-ID <[email protected]>
On Mon, 21 Dec 2015 13:33:51 -0800, masak wrote:
> <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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.