Rakudo: "Cannot invoke this object" while using custom trait that uses export trait, imported from another file

Created on 17 Feb 2018  路  4Comments  路  Source: rakudo/rakudo

The Problem

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"

Expected Behavior

Sub/method is invoked with no errors

Actual Behavior

Exception is thrown --> "Cannot invoke this object"

Steps to Reproduce

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;
    }
}

Environment

  • Operating system: macOS Sierra,
  • Compiler version (perl6 -v): This is Rakudo Star version 2018.01 built on MoarVM version 2018.01
    implementing Perl 6.c.
precompilation tests needed traits

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
[BUG] sub wrapped with mod_trait: when exported yield cryptic error message, works fine in same unit

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)

All 4 comments

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
[BUG] sub wrapped with mod_trait: when exported yield cryptic error message, works fine in same unit

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.

Was this page helpful?
0 / 5 - 0 ratings