Skip to content

Commit a1438cb

Browse files
committed
Make nqp::istype also work for roles that are part of an ancestor.
1 parent a5aed35 commit a1438cb

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/how/NQPClassHOW.nqp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,16 @@ knowhow NQPClassHOW {
421421

422422
method publish_type_cache($obj) {
423423
my @tc;
424-
for @!mro { nqp::push(@tc, $_); }
425-
for @!done { nqp::push(@tc, $_); }
424+
425+
for self.mro($obj) {
426+
nqp::push(@tc, $_);
427+
if nqp::can($_.HOW, 'role_typecheck_list') {
428+
for $_.HOW.role_typecheck_list($_) {
429+
nqp::push(@tc, $_);
430+
}
431+
}
432+
}
433+
426434
nqp::settypecache($obj, @tc)
427435
}
428436

@@ -543,6 +551,10 @@ knowhow NQPClassHOW {
543551
@!roles
544552
}
545553

554+
method role_typecheck_list($obj) {
555+
@!done;
556+
}
557+
546558
method methods($obj, :$local = 0) {
547559
if $local {
548560
@!method_order

t/nqp/056-role.t

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
plan(13);
1+
plan(15);
22

33
role R1 {
44
has $!a;
@@ -38,3 +38,12 @@ ok(!C3.HOW.does(C3, R1));
3838
ok(C3.HOW.does(C3, R3));
3939
ok(C3.HOW.does(C3, R4));
4040

41+
role Foo {
42+
}
43+
class Parent does Foo {
44+
}
45+
class Child is Parent {
46+
};
47+
48+
ok(nqp::istype(Parent, Foo), 'nqp::istype with a role directly on class');
49+
ok(nqp::istype(Child, Foo), 'nqp::istype with a role on a parent class');

0 commit comments

Comments
 (0)