Skip to content

Commit

Permalink
Correctly handle META_ASSIGN ops that don't have a name
Browse files Browse the repository at this point in the history
Because they were generated, e.g. [R~] -> [R~]=  dogbert++ for spotting
  • Loading branch information
lizmat committed Nov 15, 2018
1 parent 1ed2b09 commit 21434dd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/metaops.pm6
Expand Up @@ -2,16 +2,22 @@
my $METAOP_ASSIGN := nqp::hash;
sub METAOP_ASSIGN(\op) {
nqp::ifnull(
nqp::atkey($METAOP_ASSIGN,op.name),
nqp::atkey($METAOP_ASSIGN,nqp::objectid(op)),
METAOP_ASSIGN_NEW(op)
)
}
sub METAOP_ASSIGN_NEW(\op) {
nqp::bindkey($METAOP_ASSIGN,op.name,nqp::stmts(
nqp::bindkey($METAOP_ASSIGN,nqp::objectid(op),nqp::stmts(
(my \metaop := -> Mu \a, Mu \b {
a = op.((a.DEFINITE ?? a !! op.()), b)
}),
metaop.set_name(op.name.substr(0,*-1) ~ "=>"),
metaop.set_name(
nqp::if(
(my \name := op.name),
name.substr(0,*-1) ~ "=>",
"infix:<unnamed-op=>"
)
),
metaop
))
}
Expand Down

2 comments on commit 21434dd

@b2gills
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good thing for even more reasons, because I think the previous code would have broken the following:

my $a = 0;
$a += ~3;
say $a;
{
  multi sub infix:<+> ( \l, Str \r ) { l ~ r }
  my $a = 0;
  $a += ~3;
  say $a;
}

@lizmat
Copy link
Contributor Author

@lizmat lizmat commented on 21434dd Nov 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's exactly the reason I reverted.

Please sign in to comment.