Skip to content

Commit

Permalink
Before composition, typecheck against added roles
Browse files Browse the repository at this point in the history
Previously:

    my $type = Metamodel::ClassHOW.new_type();
    $type.^add_role(Positional);
    say $type ~~ Positional;

Would produce `False`, because we didn't put together the set of roles
to type check against until class composition time. While it's true
that we cannot resolve transitive roles and parameterizations until
that time, it's reasonable enough to answer "yes" to the roles we have
been explicitly told about before composition time.

This came up because of a regression in Spit as reported in #2056. The
previous Scalar assignment code would in some cases not enforce type
checks properly in the presence of uncomposed types. When we switched
away from the pile of C code that repeated (sort of) the type checking
logic and towards using nqp::istype, we lost this bug. However, the
module relied on it. Thankfully, we can avoid breaking the module by
applying this quite reasonable change to Rakudo.
  • Loading branch information
jnthn committed Jul 16, 2018
1 parent abfa1b1 commit 38d046f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/ClassHOW.nqp
Expand Up @@ -219,7 +219,7 @@ class Perl6::Metamodel::ClassHOW
}

method role_typecheck_list($obj) {
@!role_typecheck_list
$!composed ?? @!role_typecheck_list !! self.roles_to_compose($obj)
}

method concretization($obj, $ptype) {
Expand Down

0 comments on commit 38d046f

Please sign in to comment.