Skip to content

Instantly share code, notes, and snippets.

@zoffixznet zoffixznet/diff.diff Secret
Created Apr 4, 2017

Embed
What would you like to do?
diff --git a/src/core/traits.pm b/src/core/traits.pm
index ff15d09..ca550d4 100644
--- a/src/core/traits.pm
+++ b/src/core/traits.pm
@@ -144,6 +144,35 @@ multi sub trait_mod:<is>(Routine:D $r, :$onlystar!) {
$r.set_onlystar();
}
multi sub trait_mod:<is>(Routine:D $r, :prec(%spec)!) {
+ # "die if %spec<assoc> is "list" and $r is not an infix op"
+ # the nqp dance is because it kept failing to compile with normal Perl 6;
+ # XXX TODO: someone with more patience could figure out how to simplify it?
+ nqp::if(
+ nqp::if(
+ nqp::iseq_s(
+ 'list',
+ nqp::if(
+ nqp::istype(%spec, Pair),
+ nqp::if( # %spec is a Pair
+ nqp::iseq_s(
+ 'assoc',
+ nqp::if(
+ nqp::istype(($_ := %spec.key), Str),
+ $_, ''
+ ),
+ ),
+ nqp::istype(($_ := %spec.value), Str), $_, ''),
+ ),
+ nqp::if( # %spec is a hash
+ nqp::istype(($_ := nqp::atkey(%spec, 'assoc'), Str),
+ $_, ''
+ ),
+ ),
+ ),
+ nqp::isne_s('infix:', nqp::substr($r.name, 0, 6)),
+ ),
+ die("Cannot use `list` assoc with non-infix routines"),
+ );
my role Precedence {
has %!prec;
proto method prec(|) { * }
@@ -169,27 +198,24 @@ multi sub trait_mod:<is>(Routine:D $r, :prec(%spec)!) {
# three other trait_mod sub for equiv/tighter/looser in operators.pm
multi sub trait_mod:<is>(Routine $r, :&equiv!) {
nqp::can(&equiv, 'prec')
- ?? trait_mod:<is>($r, :prec(&equiv.prec))
+ ?? trait_mod:<is>($r, :prec(:prec(&equiv.prec('prec'))))
!! die "Routine given to equiv does not appear to be an operator";
- $r.prec<assoc>:delete;
}
multi sub trait_mod:<is>(Routine $r, :&tighter!) {
die "Routine given to tighter does not appear to be an operator"
unless nqp::can(&tighter, 'prec');
if !nqp::can($r, 'prec') || ($r.prec<prec> // "") !~~ /<[@:]>/ {
- trait_mod:<is>($r, :prec(&tighter.prec))
+ trait_mod:<is>($r, :prec(:prec(&tighter.prec('prec'))))
}
$r.prec<prec> := $r.prec<prec>.subst(/\=/, '@=');
- $r.prec<assoc>:delete;
}
multi sub trait_mod:<is>(Routine $r, :&looser!) {
die "Routine given to looser does not appear to be an operator"
unless nqp::can(&looser, 'prec');
if !nqp::can($r, 'prec') || ($r.prec<prec> // "") !~~ /<[@:]>/ {
- trait_mod:<is>($r, :prec(&looser.prec))
+ trait_mod:<is>($r, :prec(:prec(&looser.prec('prec'))))
}
$r.prec<prec> := $r.prec<prec>.subst(/\=/, ':=');
- $r.prec<assoc>:delete;
}
multi sub trait_mod:<is>(Routine $r, :$assoc!) {
trait_mod:<is>($r, :prec({ :$assoc }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.