# New Ticket Created by  Zefram 
# Please include the string:  [perl #127011]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127011 >


> my Int $a = Inf
Cannot find method 'value'
> my Int $a = NaN
Cannot find method 'value'

It is correct that these statements produce exceptions, but this
particular exception does not describe the situation well.  A much better
exception in produced when initialising to a regular Num:

> my Int $a = 3.5e0
===SORRY!=== Error while compiling <unknown file>
Cannot assign a literal of type Num (3.5e0) to a variable of type Int. You can 
declare the variable to be of type Real, or try to coerce the value with 
3.5e0.Int or Int(3.5e0), or just write the value as 3
at <unknown file>:1
------> my Int $a = ^3.5e0

A much more mundane exception is produced if the initialising value
is not stated as a literal, and in this case the message is consistent
between kinds of Num:

> my $b = Inf
Inf
> my Int $a = $b
Type check failed in assignment to $a; expected Int but got Num
  in block <unit> at <unknown file>:1
> my $b = 3.5e0
3.5
> my Int $a = $b
Type check failed in assignment to $a; expected Int but got Num
  in block <unit> at <unknown file>:1

-zefram

Reply via email to