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

Errors in Int() coercer #6298

Open
p6rt opened this issue May 31, 2017 · 2 comments
Open

Errors in Int() coercer #6298

p6rt opened this issue May 31, 2017 · 2 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented May 31, 2017

Migrated from rt.perl.org#131413 (status was 'new')

Searchable as RT131413$

@p6rt
Copy link
Author

p6rt commented May 31, 2017

From @zoffixznet

The first one says it expected Int but got Str, when in reality the type constraint is Any-to-Int​:D coercer.

The second one talks about Int methods, but I ain't calling any. IMO the coercer should catch such errors when calling the method and report them as type check failure instead.

18​:34 Zoffix m​: sub (Int​:D()) {}( Str )
18​:34 camelia rakudo-moar fb7dd8​: OUTPUT​: «Type check failed in binding to parameter '<anon>'; expected Int but got Str (Str)␤ in sub at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

18​:34 Zoffix m​: sub (Int()) {}( Str )
18​:34 camelia rakudo-moar fb7dd8​: OUTPUT​: «Invocant of method 'Int' must be an object instance of type 'Str', not a type object of type 'Str'. Did you forget a '.new'?␤ in sub at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

@p6rt p6rt added the LTA Less Than Awesome; typically an error message that could be better label Jan 5, 2020
@usev6
Copy link

usev6 commented Oct 7, 2023

Nowadays the output looks like this:

$ ./rakudo-m -e 'sub (Int:D()) {}( Str )'
Parameter '<anon>' of routine '<anon>' must be an object instance of
type 'Int:D(Any)', not a type object of type 'Str'.  Did you forget a
'.new'?
  in sub  at -e line 1
  in block <unit> at -e line 1

$ ./rakudo-m -e 'sub (Int()) {}( Str )'
Cannot create an Int from a 'Str' type object
  in sub  at -e line 1
  in block <unit> at -e line 1

The second evaluation fails with X::AdHoc. But in general the new behavior looks sensible to me.

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

2 participants