Skip Menu |
Report information
Id: 130761
Status: open
Worked: 5 min
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: moritz <moritz.lenz [at] googlemail.com>
Cc:
AdminCc:

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



Date: Sat, 11 Feb 2017 12:28:45 +0100
To: rakudobug [...] perl.org
From: Moritz Lenz <moritz [...] faui2k3.org>
Subject: An if-block confuses &ROUTINE to point at the wrong outer routine
Download (untitled) / with headers
text/plain 415b
sub f($x) { sub { if True { say &?ROUTINE.name } } }.(42)() This prints f on Rakudo 2017.01-170-gc0a907f built on MoarVM version 2017.01-31-g20dfa6b &?ROUTINE should refer to the inner, anonymous subroutine here, not to &f. The same bug happens if the inner subroutine is named, but not if the "if"-block is absent. -- Moritz Lenz https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/
Subject: test added
Download (untitled) / with headers
text/plain 1024b
Test added here: https://github.com/perl6/roast/commit/ce7fb0f723 commit ce7fb0f72346dbe6da1629b5af978b9c97d31e4d Author: Moritz Lenz <moritz@faui2k3.org> Date: Mon Feb 13 08:24:04 2017 +0100 RT #130761: if-block confuses &?ROUTINE diff --git a/S02-magicals/sub.t b/S02-magicals/sub.t index 417df28..7021230 100644 --- a/S02-magicals/sub.t +++ b/S02-magicals/sub.t @@ -8,7 +8,7 @@ This tests the &?ROUTINE magical value =end comment -plan 10; +plan 11; # L<S06/The C<&?ROUTINE> object> # L<S02/Names/Which routine am I in> @@ -69,4 +69,18 @@ is($result3, 6, 'the &?ROUTINE magical works correctly in overloaded operators' is @collected.join(''), 'aaaa', 'Correct closure semantics with &?ROUTINE in nested closure'; } +# RT #130761 + +{ + sub f() { + sub g() { + if True { + return &?ROUTINE.name; + } + } + } + #?rakudo todo 'RT #130761' + is f()(), 'g', 'Inner blocks are transparent to &?ROUTINE (RT#130761)'; +} + # vim: ft=perl6
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 654b
On Sat, 11 Feb 2017 03:29:18 -0800, moritz wrote: Show quoted text
> sub f($x) { > sub { > if True { > say &?ROUTINE.name > } > } > }.(42)() > > This prints f on Rakudo 2017.01-170-gc0a907f built on MoarVM version > 2017.01-31-g20dfa6b > > &?ROUTINE should refer to the inner, anonymous subroutine here, not to > &f. The same bug happens if the inner subroutine is named, but not if > the "if"-block is absent. > >
Seems an optimizer bug. Goes away if you switch it off: $ perl6 --optimize=3 -e 'sub f($x) { sub y { if True { say &?ROUTINE.name } } }.(42)()' f $ perl6 --optimize=off -e 'sub f($x) { sub y { if True { say &?ROUTINE.name } } }.(42)()' y


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