Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created April 17, 2015 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FROGGS/d1b09046bed6dd01ab56 to your computer and use it in GitHub Desktop.
Save FROGGS/d1b09046bed6dd01ab56 to your computer and use it in GitHub Desktop.
diff --git a/src/core/traits.pm b/src/core/traits.pm
index c0e961a..e4d70fe 100644
--- a/src/core/traits.pm
+++ b/src/core/traits.pm
@@ -187,6 +187,18 @@ multi sub trait_mod:<is>(Routine $r, :&tighter!) {
}
$r.prec<prec> := $r.prec<prec>.subst(/\=/, '@=');
$r.prec<assoc>:delete;
+ if $r.prec<prec> le 'w=' {
+ my $name := $r.name;
+ if $name.starts-with('prefix:') {
+ die 'Precedence of a prefix must be tighter then any infix'
+ }
+ elsif $name.starts-with('postfix:') {
+ die 'Precedence of a postfix must be tighter then any infix'
+ }
+ elsif $name.starts-with('postcircumfix:') {
+ die 'Precedence of a postcircumfix must be tighter then any infix'
+ }
+ }
}
multi sub trait_mod:<is>(Routine $r, :&looser!) {
die "Routine given to looser does not appear to be an operator"
@@ -196,6 +208,18 @@ multi sub trait_mod:<is>(Routine $r, :&looser!) {
}
$r.prec<prec> := $r.prec<prec>.subst(/\=/, ':=');
$r.prec<assoc>:delete;
+ if $r.prec<prec> le 'w=' {
+ my $name := $r.name;
+ if $name.starts-with('prefix:') {
+ die 'Precedence of a prefix must be tighter then any infix'
+ }
+ elsif $name.starts-with('postfix:') {
+ die 'Precedence of a postfix must be tighter then any infix'
+ }
+ elsif $name.starts-with('postcircumfix:') {
+ die 'Precedence of a postcircumfix must be tighter then any infix'
+ }
+ }
}
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