Skip to content

Commit

Permalink
Storing Inf/NaN in Int throws with proper error
Browse files Browse the repository at this point in the history
RT#126990
RT#127207 (dupe)
  • Loading branch information
zoffixznet committed Jul 11, 2016
1 parent b38fe5e commit 679a57f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion S02-types/infinity.t
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 13;
plan 15;

# L<S02/"Infinity and C<NaN>" /Perl 6 by default makes standard IEEE floating point concepts visible>

Expand Down Expand Up @@ -50,4 +50,15 @@ ok (-Inf).Int === (-Inf), 'Inf.Int === Int';
ok ( rand * Inf ) === Inf, 'multiply rand by Inf without maximum recursion depth exceeded';
}

{
#RT #126990
throws-like { my Int $x = Inf }, X::TypeCheck::Assignment,
message => /'expected Int but got Num (Inf)'/,
"trying to assign Inf to Int gives a helpful error";

my Num $x = Inf;
is $x, Inf, 'assigning Inf to Num works without errors';
}


# vim: ft=perl6
13 changes: 12 additions & 1 deletion S02-types/nan.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 21;
plan 23;

# Undeterminate Math results
# see L<"http://mathworld.wolfram.com/Indeterminate.html">
Expand Down Expand Up @@ -44,4 +44,15 @@ is NaN.perl, 'NaN', 'NaN perlification ok';
#RT #83622
ok NaN===NaN, "NaN value identity";

{
#RT #126990
throws-like { my Int $x = NaN }, X::TypeCheck::Assignment,
message => /'expected Int but got Num (NaN)'/,
"trying to assign NaN to Int gives a helpful error";

my Num $x = NaN;
is $x, NaN, 'assigning NaN to Num works without errors';
}


# vim: ft=perl6

0 comments on commit 679a57f

Please sign in to comment.