Skip to content

Commit

Permalink
Merge pull request #4708 from vrurg/rakudo-4705-libxml
Browse files Browse the repository at this point in the history
Protect some typechecks with try
  • Loading branch information
vrurg committed Jan 10, 2022
2 parents fc4a027 + e3f2214 commit a90369e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Perl6/Optimizer.nqp
Expand Up @@ -1578,7 +1578,9 @@ my class SmartmatchOptimizer {

return nqp::null() if $lhs.value.HOW.archetypes.generic;

my $matches := nqp::istype($lhs.value, $rhs.value);
# Wrap into try because for if there a user-defined `where`-block involved into typematching it might throw.
# Consider this case a failed typematch and proceed further.
my $matches := try nqp::istype($lhs.value, $rhs.value);
# If LHS is an invocation or a variable then we actually check their (return) type. In this case non-match
# means nothing because their eventual value could still match at runtime. Yet true means that any of their
# value will always match. Also, if routine returns a constant then we can always use it too.
Expand Down Expand Up @@ -1618,7 +1620,7 @@ my class SmartmatchOptimizer {
my $try-it := 1;
my $rhs-type := nqp::what($rhs.value);
for @literal-rhs-exceptions {
last unless $try-it := $try-it && !nqp::istype($rhs-type, $_);
last unless $try-it := $try-it && !try nqp::istype($rhs-type, $_);
note($rhs-type.HOW.name($rhs-type), " is not ", $_.HOW.name($_)) if $!debug;
}
if $try-it {
Expand Down

0 comments on commit a90369e

Please sign in to comment.