Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (74 sloc) 2.04 KB
use v6;
use Test;
plan 19;
=begin pod
Test attributes with recursively typed attributes
=end pod
class A {
has A $.attr is rw;
my A $a;
my A $b;
lives_ok {
$a .= new();
$b .= new(:attr($a));
}, 'Can instantiate class with recursively-typed attribute';
isa_ok $a, 'A', 'Sanity check, $a is of type A';
ok $b.attr === $a, "Recursively-typed attribute stores correctly";
lives_ok { $a.attr = $b; }, "Cycles are fine";
ok $b.attr.attr === $b, "Cycles resolve correctly";
#L<S12/Attributes/"Class attributes are declared">
#?rakudo skip 'class attributes NYI'
class B {
my B $.attr is rw;
my B $a;
lives_ok {
$a .= new();
B.attr = $a;
}, "Can instantiate class with recursively-typed class lexical";
ok B.attr === $a, "Recursively-typed class lexical stores correctly";
#L<S12/Methods/current lexically-determined class ::?CLASS>
#?rakudo skip '::?CLASS'
class C {
has ::?CLASS $.attr is rw;
my C $a;
my C $b;
lives_ok {
$a .= new();
$b .= new(:attr($a));
}, 'Can instantiate class with ::?CLASS attribute';
is $b.attr, $a, '::?CLASS attribute stores correctly';
lives_ok { $a.attr = $b; }, '::?CLASS cycles are fine';
ok $b.attr.attr === $b, '::?CLASS cycles resolve correctly';
lives_ok { $a.attr .= new(); }, 'Can instantiate attribute of type ::?CLASS';
isa_ok $a.attr, C, '::?CLASS instantiates to correct class';
class D is C { };
my D $d;
lives_ok {
$d .= new();
$d.attr .= new();
}, 'Can instantiate derived class with ::?CLASS attribute';
#?pugs todo 'bug'
isa_ok $d.attr, C, '::?CLASS is lexical, not virtual';
# RT #67236
class Z {
has Z is rw;
my $good_a =;
lives_ok { $[0] = }, 'can assign';
isa_ok $[0], Z;
my $bad_a =;
lives_ok { $ ) }, 'can push';
isa_ok $[0], Z;
# vim: ft=perl6
Jump to Line
Something went wrong with that request. Please try again.