Invoking a sub/method which has a custom trait produces the error "Cannot invoke this object" when that custom trait is imported from another file and has the "is export" trait, but only when the sub/method itself is imported from another file and has "is export"
Sub/method is invoked with no errors
Exception is thrown --> "Cannot invoke this object"
Create 3 files below and run perl6 main.pl6
main.pl6
use lib './';
use foo;
sub MAIN() {
bar();
}
foo.pm
use customtrait;
sub bar() is export is customtrait {
say "Hello";
}
customtrait.pm
multi sub trait_mod:<is>(Sub $m, :$customtrait!) is export {
$m.wrap: sub (|) {
nextsame;
}
}
perl6 -v): This is Rakudo Star version 2018.01 built on MoarVM version 2018.01Some of the likely-related tickets in the same area:
RT#121991聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=121991聽
[@ LARRY] Unless 'use soft' is in play, .wrap should die in Rakudo
RT#129096聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=129096聽
[BUG] sub wrapped with mod_trait:
RT#128476聽[new]:聽https://rt.perl.org/Ticket/Display.html?id=128476
聽[SEGV] .wrap causes segfault when wrapping core sub and using that sub in a module that uses the module that wraps
RT#127860聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=127860聽
[BUG][PRECOMP] Wrapped method fails when precompiled
RT#125634聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=125634
聽[BUG] Using a compiled (mbc) wrapping trait: Cannot invoke this object (REPR: Null, cs = 0)
Adding no precompilation; to the top of customtrait.pm "fixes" the issue.
This appears to be working as expected in Rakudo version 2020.01.
Opening as it needs tests.
Most helpful comment
Some of the likely-related tickets in the same area:
RT#121991聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=121991聽
[@ LARRY] Unless 'use soft' is in play, .wrap should die in Rakudo
RT#129096聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=129096聽 when exported yield cryptic error message, works fine in same unit
[BUG] sub wrapped with mod_trait:
RT#128476聽[new]:聽https://rt.perl.org/Ticket/Display.html?id=128476
聽[SEGV] .wrap causes segfault when wrapping core sub and using that sub in a module that uses the module that wraps
RT#127860聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=127860聽
[BUG][PRECOMP] Wrapped method fails when precompiled
RT#125634聽[open]:聽https://rt.perl.org/Ticket/Display.html?id=125634
聽[BUG] Using a compiled (mbc) wrapping trait: Cannot invoke this object (REPR: Null, cs = 0)