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

An if-block confuses &?ROUTINE to point at the wrong outer routine #6065

Open
p6rt opened this issue Feb 11, 2017 · 7 comments
Open

An if-block confuses &?ROUTINE to point at the wrong outer routine #6065

p6rt opened this issue Feb 11, 2017 · 7 comments

Comments

@p6rt
Copy link

@p6rt p6rt commented Feb 11, 2017

Migrated from rt.perl.org#130761 (status was 'open')

Searchable as RT130761$

@p6rt
Copy link
Author

@p6rt p6rt commented Feb 11, 2017

From @moritz

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/

@p6rt
Copy link
Author

@p6rt p6rt commented Feb 13, 2017

From @moritz

Test added here​: Raku/roast@ce7fb0f

commit ce7fb0f72346dbe6da1629b5af978b9c97d31e4d
Author​: Moritz Lenz <moritz@​faui2k3.org>
Date​: Mon Feb 13 08​:24​:04 2017 +0100

  RT #​130761​: if-block confuses &?ROUTINE

Inline Patch
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
@p6rt
Copy link
Author

@p6rt p6rt commented Feb 14, 2017

From @zoffixznet

On Sat, 11 Feb 2017 03​:29​:18 -0800, moritz wrote​:

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

@p6rt
Copy link
Author

@p6rt p6rt commented Feb 14, 2017

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

@p6rt
Copy link
Author

@p6rt p6rt commented Apr 5, 2019

From @usev6

Just for the record​: This seems to work on the JVM backend​:

$ ./perl6-j --optimize=3 -e 'sub f() { sub g() { if True { return &?ROUTINE.name } } }; say f()()'
g

I'm going to unfudge the test in S02-magicals/sub.t for rakudo.jvm.

1 similar comment
@p6rt
Copy link
Author

@p6rt p6rt commented Apr 5, 2019

From @usev6

Just for the record​: This seems to work on the JVM backend​:

$ ./perl6-j --optimize=3 -e 'sub f() { sub g() { if True { return &?ROUTINE.name } } }; say f()()'
g

I'm going to unfudge the test in S02-magicals/sub.t for rakudo.jvm.

@p6rt
Copy link
Author

@p6rt p6rt commented Apr 5, 2019

From @usev6

On Thu, 04 Apr 2019 22​:59​:38 -0700, bartolin@​gmx.de wrote​:

I'm going to unfudge the test in S02-magicals/sub.t for rakudo.jvm.

For the record​: Raku/roast@aaf7ad0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.