Skip to content

Instantly share code, notes, and snippets.

@dmaestro
Created September 9, 2018 21:44
Show Gist options
  • Save dmaestro/826f4a602136606b8db98a1c72785ef2 to your computer and use it in GitHub Desktop.
Save dmaestro/826f4a602136606b8db98a1c72785ef2 to your computer and use it in GitHub Desktop.
Delegation fails with "Cannot invoke this object" when this package is used
unit package TestD;
role R {
method foo( --> Int ) { ... }
}
class C {
has R $.delegate
handles *
is required;
}
class D does R {
has Int $.foo;
}
@dmaestro
Copy link
Author

dmaestro commented Sep 9, 2018

Place file in ./lib, run command:

$ perl6 -Ilib -MTestD -e 'my $d = TestD::D.new(:foo(2)); my $c = TestD::C.new(delegate => $d); say $d.foo; say $c.foo'
2
Cannot invoke this object (REPR: Null; VMNull)
 in block <unit> at -e line 1

The one-liner version works fine:

$ perl6 -e 'package TestD { role R { method foo(-->Int) {...} }; class C { has R $.delegate handles * is required; }; class D does R { has Int $.foo; }; }; my $d = TestD::D.new(:foo(2)); my $c = TestD::C.new(delegate => $d); say $d.foo; say $c.foo'
2
2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment