From f6091476486d29c8886da83402edbfd29d03c3f2 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Thu, 17 Dec 2015 11:03:22 +0100 Subject: [PATCH] Make error on 123 +< (1 +< 64) little more awesome Also for +> . Adds error class X::NYI::BigInt, perhaps also useful for other cases. In response to RT #126941. --- src/core/Exception.pm | 8 ++++++++ src/core/Int.pm | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/Exception.pm b/src/core/Exception.pm index e8bdcf1b2d0..db3ba24d9f8 100644 --- a/src/core/Exception.pm +++ b/src/core/Exception.pm @@ -629,6 +629,14 @@ my class X::NYI::Available is X::NYI { "Please install { self.available-str } for $.feature support. " } } +my class X::NYI::BigInt is Exception { + has $.op; + has $.big; + has $.side = 'right'; + method message() { + "Big integer $!big not yet supported on {$!side}hand side of '$!op' operator" + } +} my class X::Experimental does X::Comp { has $.feature; method message() { "Use of $.feature is experimental; please 'use experimental :$.feature'" } diff --git a/src/core/Int.pm b/src/core/Int.pm index 870ba361e4d..4a45fb16f17 100644 --- a/src/core/Int.pm +++ b/src/core/Int.pm @@ -1,5 +1,6 @@ my class Rat { ... } my class X::Numeric::DivideByZero { ... } +my class X::NYI::BigInt { ... } my class Int { ... } my subset UInt of Int where * >= 0; @@ -351,14 +352,18 @@ multi sub infix:<+^>(int $a, int $b) { } multi sub infix:«+<»(Int:D \a, Int:D \b) returns Int:D { - nqp::bitshiftl_I(nqp::decont(a), nqp::unbox_i(b), Int) + nqp::isbig_I(nqp::decont(b)) + ?? fail X::NYI::BigInt.new(:op('+<'),:big(b)) + !! nqp::bitshiftl_I(nqp::decont(a), nqp::unbox_i(b), Int) } multi sub infix:«+<»(int $a, int $b) { nqp::bitshiftl_i($a, $b); } multi sub infix:«+>»(Int:D \a, Int:D \b) returns Int:D { - nqp::bitshiftr_I(nqp::decont(a), nqp::unbox_i(b), Int) + nqp::isbig_I(nqp::decont(b)) + ?? fail X::NYI::BigInt.new(:op('+>'),:big(b)) + !! nqp::bitshiftr_I(nqp::decont(a), nqp::unbox_i(b), Int) } multi sub infix:«+>»(int $a, int $b) { nqp::bitshiftr_i($a, $b)