Skip Menu |
Report information
Id: 125523
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: drforr [at] pobox.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: Rakudobug <rakudobug [...] perl.org>
Subject: NativeCall num64 not properly defaulting
From: drforr [...] pobox.com
Date: Wed, 01 Jul 2015 21:43:52 +0200
Download (untitled) / with headers
text/plain 722b
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--
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:
Show quoted text
> 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--


RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 896b
On Mon, 02 Oct 2017 18:09:45 -0700, alex.jakimenko@gmail.com wrote: Show quoted text
> 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. Show quoted text
> 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. Show quoted text
> 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.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org