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
Loop variable in BEGIN block becomes a VMNull #2379
Comments
FWIW this is not a recent regression: https://gist.github.com/1d7ab9005e3c53fae9b91c5fcfdbe1f2 |
Some more investigation indicates it's not the loop per se that's essential in triggering this, but it needs a scope below the main BEGIN one |
Doesn't look like even that is necessary. Just a core routine call inside the added method: # Foo.pm6
unit class Foo;
BEGIN { $?CLASS.^add_method: 'foo', { join } }
# script.p6
use lib '.';
use Foo;
Foo.foo;
# OUTPUT: Cannot invoke this object (REPR: Null; VMNull) And it happens only for core routine calls, not ones you define inside And if you define a routine outside the begin and try to use it, you get a different error: # Foo.pm6
unit class Foo;
sub join {}
BEGIN { $?CLASS.^add_method: 'foo', { join } }
# script.p6
use lib '.';
use Foo;
Foo.foo;
# OUTPUT: getlex: outer index out of range |
Found what could possibly be a workaround you could use: assign a sub you want to use to another symbol inside
|
That only work because
|
Yeah, I guess it's fairly limited; you have to extract unit class Foo;
BEGIN {
my &dd2 = ⅆ my &sym2 = sub ($arg) { dd2 $arg };
$?CLASS.^add_method: 'foo', { sym2 42 } } |
This would probably be the place to start looking at: https://github.com/rakudo/rakudo/blob/master/src/Perl6/World.nqp#L2636 |
That isn't going to help in my use-case, where I need to do this over many values. |
That does indeed look like it deals with the outermost BEGIN scope and not further. Not that I'd know how to fix that. |
FWIW, a similar issue exists with:
|
Tested on 2019.07.1 – fails. Closing via MoarVM/MoarVM#1209 and 7e3d023 |
The Problem
This code:
when run as
fails with
unless one adds
no precomplication
to the class.Environment
This is Rakudo version 2018.09 built on MoarVM version 2018.09
The text was updated successfully, but these errors were encountered: