Skip to content

Commit

Permalink
Fail with a typed exception when failing Num.Int
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Oct 4, 2017
1 parent 2e72652 commit f04bd1d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/Num.pm
@@ -1,5 +1,6 @@
my class X::Numeric::DivideByZero { ... };
my role Rational { ... };
my class X::Numeric::DivideByZero { ... }
my class X::Numeric::CannotConvert { ... }
my role Rational { ... }

my class Num does Real { # declared in BOOTSTRAP
# class Num is Cool
Expand All @@ -24,7 +25,7 @@ my class Num does Real { # declared in BOOTSTRAP

method Int(Num:D:) {
nqp::isnanorinf(nqp::unbox_n(self))
?? Failure.new("Cannot coerce {self} to an Int")
?? X::Numeric::CannotConvert.new(:source(self), :target(Int)).fail
!! nqp::fromnum_I(nqp::unbox_n(self),Int)
}

Expand Down

0 comments on commit f04bd1d

Please sign in to comment.