Skip to content

Commit

Permalink
Make nqp::istype also work for roles that are part of an ancestor.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jan 13, 2017
1 parent a5aed35 commit a1438cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/how/NQPClassHOW.nqp
Expand Up @@ -421,8 +421,16 @@ knowhow NQPClassHOW {

method publish_type_cache($obj) {
my @tc;
for @!mro { nqp::push(@tc, $_); }
for @!done { nqp::push(@tc, $_); }

for self.mro($obj) {
nqp::push(@tc, $_);
if nqp::can($_.HOW, 'role_typecheck_list') {
for $_.HOW.role_typecheck_list($_) {
nqp::push(@tc, $_);
}
}
}

nqp::settypecache($obj, @tc)
}

Expand Down Expand Up @@ -543,6 +551,10 @@ knowhow NQPClassHOW {
@!roles
}

method role_typecheck_list($obj) {
@!done;
}

method methods($obj, :$local = 0) {
if $local {
@!method_order
Expand Down
11 changes: 10 additions & 1 deletion t/nqp/056-role.t
@@ -1,4 +1,4 @@
plan(13);
plan(15);

role R1 {
has $!a;
Expand Down Expand Up @@ -38,3 +38,12 @@ ok(!C3.HOW.does(C3, R1));
ok(C3.HOW.does(C3, R3));
ok(C3.HOW.does(C3, R4));

role Foo {
}
class Parent does Foo {
}
class Child is Parent {
};

ok(nqp::istype(Parent, Foo), 'nqp::istype with a role directly on class');
ok(nqp::istype(Child, Foo), 'nqp::istype with a role on a parent class');

0 comments on commit a1438cb

Please sign in to comment.