Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad error when initialising Int var to Inf or NaN #4916

Closed
p6rt opened this issue Dec 24, 2015 · 6 comments
Closed

bad error when initialising Int var to Inf or NaN #4916

p6rt opened this issue Dec 24, 2015 · 6 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Dec 24, 2015

Migrated from rt.perl.org#127011 (status was 'resolved')

Searchable as RT127011$

@p6rt
Copy link
Author

p6rt commented Dec 24, 2015

From zefram@fysh.org

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

@p6rt
Copy link
Author

p6rt commented Dec 24, 2015

@p6rt
Copy link
Author

p6rt commented Dec 24, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 24, 2015

From zefram@fysh.org

Alex Jakimenko via RT wrote​:

See this​: https://rt.perl.org/Public/Bug/Display.html?id=126990

Ah, quite right. My [perl #​127011] duplicates the "LTA error message"
portion of your [perl #​126990]. Mine can therefore be closed, if the
.Range portion of yours doesn't confound dealing with the issue there.

-zefram

@p6rt
Copy link
Author

p6rt commented Mar 9, 2018

From @dogbert17

Duplicate of #​126990 which has been resolved.

@p6rt
Copy link
Author

p6rt commented Mar 9, 2018

@dogbert17 - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 9, 2018
@p6rt p6rt added the LTA Less Than Awesome; typically an error message that could be better label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

1 participant