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

Remove P6opauqe from unboxing errors #4371

Open
p6rt opened this issue Jul 1, 2015 · 4 comments
Open

Remove P6opauqe from unboxing errors #4371

p6rt opened this issue Jul 1, 2015 · 4 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Jul 1, 2015

Migrated from rt.perl.org#125523 (status was 'open')

Searchable as RT125523$

@p6rt
Copy link
Author

p6rt commented Jul 1, 2015

From @drforr

num64 should be a floating-point type as per the docs, so $value = 1.0
should be a reasonable floating-point default value for a function call.
It's not an issue of being inappropriately downgraded to an int, because
'$value = 1.1' returns the same error.

--cut here--
sub cvDivide( OpenCV2​::Arr $arr,
  num64 $scale = 1.0, num64 $range = 0.0 )
  is native(LIB)
cvDivide( OpenCV2​::Arr.new );
--cut here--

throws this error instead​:

--cut here--
prove -e'perl6 -Ilib'
t/01-load.t ........ ===SORRY!===
Default value '1' will never bind to a parameter of type num64
at /home/jgoff/Repositories/perl6-OpenCV2/lib/OpenCV2/Arr.pm​:412
------> num64 $scale = 1.0⏏,

--cut here--

@p6rt
Copy link
Author

p6rt commented Oct 3, 2017

From @AlexDaniel

Right, because it's a Rat.

sub foo(num64 $scale = 1.0)     {}; say foo # This type cannot unbox to a native number​: P6opaque, Rat
sub foo(num64 $scale = 1.0.Num) {}; say foo # Nil

I don't know what is the consensus on this one, but having to .Num your values is rather reasonable.

The error message is LTA though.

On 2015-07-01 12​:44​:09, drforr@​pobox.com wrote​:

num64 should be a floating-point type as per the docs, so $value = 1.0
should be a reasonable floating-point default value for a function call.
It's not an issue of being inappropriately downgraded to an int, because
'$value = 1.1' returns the same error.

--cut here--
sub cvDivide( OpenCV2​::Arr $arr,
num64 $scale = 1.0, num64 $range = 0.0 )
is native(LIB)
cvDivide( OpenCV2​::Arr.new );
--cut here--

throws this error instead​:

--cut here--
prove -e'perl6 -Ilib'
t/01-load.t ........ ===SORRY!===
Default value '1' will never bind to a parameter of type num64
at /home/jgoff/Repositories/perl6-OpenCV2/lib/OpenCV2/Arr.pm​:412
------> num64 $scale = 1.0⏏,

--cut here--

@p6rt
Copy link
Author

p6rt commented Oct 3, 2017

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

@p6rt
Copy link
Author

p6rt commented Oct 5, 2017

From @jnthn

On Mon, 02 Oct 2017 18​:09​:45 -0700, alex.jakimenko@​gmail.com wrote​:

Right, because it's a Rat.

sub foo(num64 $scale = 1.0) {}; say foo # This type cannot unbox to a
native
number​: P6opaque, Rat
sub foo(num64 $scale = 1.0.Num) {}; say foo # Nil

No need for .Num, just write it as 1e0 so it's a Num literal.

I don't know what is the consensus on this one, but having to .Num
your values
is rather reasonable.

The rule is simple​: types in Perl 6 are constraints. We do go as far as letting literals play the role of both a native and a boxed (int/Int, num/Num), but no further.

The error message is LTA though.

What would you like it to say? It seems to contain all relevant information we can reasonably provide in a runtime error (what we tried to unbox it to, and what type it was); the mention of P6opauqe could go away, though, as it doesn't really add anything.

@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