Skip to content

Commit

Permalink
Streamline Metamodel::SubsetHOW (Part 2/N)
Browse files Browse the repository at this point in the history
Specifically .accepts_type by using attribute shortcut and moving
the ternary to avoid repeating code
  • Loading branch information
lizmat committed Apr 12, 2024
1 parent e7d7261 commit 309686a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Perl6/Metamodel/SubsetHOW.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,19 @@ class Perl6::Metamodel::SubsetHOW

# Here we check the value itself (when on RHS on smartmatch).
method accepts_type($XXX, $checkee) {
my $refinee := $!refinee;

nqp::hllboolfor(
nqp::istype($checkee, $!refinee) &&
(nqp::isnull($!refinement)
|| ($!refinee.HOW.archetypes($!refinee).coercive
?? nqp::istrue($!refinement.ACCEPTS($!refinee.HOW.coerce($!refinee, $checkee)))
!! nqp::istrue($!refinement.ACCEPTS($checkee)))),
"Raku")
nqp::istype($checkee, $refinee)
&& (nqp::isnull($!refinement)
|| nqp::istrue($!refinement.ACCEPTS(
$refinee.HOW.archetypes($refinee).coercive
?? $refinee.HOW.coerce($refinee, $checkee)
!! $checkee
))
),
"Raku"
)
}

# Methods needed by Perl6::Metamodel::Nominalizable
Expand Down

0 comments on commit 309686a

Please sign in to comment.