Skip to content

Commit 679a57f

Browse files
committed
Storing Inf/NaN in Int throws with proper error
RT#126990 RT#127207 (dupe)
1 parent b38fe5e commit 679a57f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

S02-types/infinity.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use v6;
22
use Test;
3-
plan 13;
3+
plan 15;
44

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

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

53+
{
54+
#RT #126990
55+
throws-like { my Int $x = Inf }, X::TypeCheck::Assignment,
56+
message => /'expected Int but got Num (Inf)'/,
57+
"trying to assign Inf to Int gives a helpful error";
58+
59+
my Num $x = Inf;
60+
is $x, Inf, 'assigning Inf to Num works without errors';
61+
}
62+
63+
5364
# vim: ft=perl6

S02-types/nan.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v6;
22

33
use Test;
44

5-
plan 21;
5+
plan 23;
66

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

47+
{
48+
#RT #126990
49+
throws-like { my Int $x = NaN }, X::TypeCheck::Assignment,
50+
message => /'expected Int but got Num (NaN)'/,
51+
"trying to assign NaN to Int gives a helpful error";
52+
53+
my Num $x = NaN;
54+
is $x, NaN, 'assigning NaN to Num works without errors';
55+
}
56+
57+
4758
# vim: ft=perl6

0 commit comments

Comments
 (0)