Skip to content

Commit

Permalink
Fix smartmatch over topic
Browse files Browse the repository at this point in the history
Previously `ACCEPTS` was caled inside topic temporarization causing
`$rhs` being an expression containing a topic to use the temporary one
bound to RHS.

Cases not resolved:

    "aaa" ~~ { $_ } given /\w/; # "aaa"

Because Code.ACCEPTS doesn't boolify

The following is currently wrong too:

    "aaa" ~~ {$_}() given rx/\w+/

The topic must pick up the temporary value but `given` one is taken
instead.
  • Loading branch information
vrurg committed Nov 21, 2022
1 parent 46d8c1a commit f1f757c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Raku/ast/expressions.rakumod
Expand Up @@ -233,21 +233,24 @@ class RakuAST::Infix is RakuAST::Infixish is RakuAST::Lookup {

method IMPL-SMARTMATCH-QAST(RakuAST::IMPL::QASTContext $context, Mu $left-qast,
Mu $right-qast, int $negate) {
my $rhs-local := QAST::Node.unique('sm-rhs');
my $accepts-call := QAST::Op.new(
:op('callmethod'), :name('ACCEPTS'),
$right-qast,
QAST::Var.new( :name('$_'), :scope('lexical') )
);
QAST::Var.new(:name($rhs-local), :scope<local>),
QAST::Var.new( :name('$_'), :scope('lexical') ));
if $negate {
$accepts-call := QAST::Op.new(
:op('hllbool'),
QAST::Op.new(
:op('not_i'),
QAST::Op.new( :op('istrue'), $accepts-call )
)
);
QAST::Op.new( :op('istrue'), $accepts-call )));
}
self.IMPL-TEMPORARIZE-TOPIC($left-qast, $accepts-call)
QAST::Stmts.new(
QAST::Op.new(
:op('bind'),
QAST::Var.new(:name($rhs-local), :scope<local>, :decl<var>),
$right-qast ),
self.IMPL-TEMPORARIZE-TOPIC($left-qast, $accepts-call))
}

method IMPL-LIST-INFIX-QAST(RakuAST::IMPL::QASTContext $context, Mu $operands) {
Expand Down

0 comments on commit f1f757c

Please sign in to comment.