Might be because there's a prefix form of + with a wider type? "Every DWIM
has a WAT"

On Sun, Sep 30, 2018 at 9:55 AM Fernando Santagata <
nando.santag...@gmail.com> wrote:

> What I was pointing out is that the '*' operator outputs an error, and I
> was expecting that, while the '+' doesn't.
> Besides, the '+' delivers the correct result, which apparently indicates
> that the two operators are treated differently.
>
> I was trying to understand whether this behavior is inherent to the Perl 6
> type system or it's just a bug.
>
> On Sun, Sep 30, 2018, 12:27 JJ Merelo <jjmer...@gmail.com> wrote:
>
>> This works:
>>
>> my int32 $a = 3; my int32 $b = 7; say $a * $b # OUTPUT: «21␤»
>>
>> El dom., 30 sept. 2018 a las 11:28, Fernando Santagata (<
>> nando.santag...@gmail.com>) escribió:
>>
>>> Hi,
>>>
>>> I was hunting for a bug in my code, this one:
>>>
>>> my @a := CArray[int32].new: 6,3;
>>> say [+] @a; # it should be "say [+] @a.list;"
>>>
>>> That statement prints "9", while changing the '+' with a '*' it
>>> generates an error, as it should:
>>>
>>> Cannot resolve caller Numeric(NativeCall::Types::CArray[int32]: ); none
>>> of these signatures match:
>>>     (Mu:U \v: *%_)
>>>
>>> Is this a bug, an inconsistency, or a necessary evil?
>>>
>>
>> It's difficult to say. Some conversion is taking place somewhere to
>> Numeric, and it's getting stuff it does not like. The type is
>> NativeCall::Types::CArray[int32].new and it's being considered a single
>> item; it's attempting conversion to Numeric. The thing here is that CArray
>> is actually not an Array; it inherits directly from Any:
>>
>>     say @a.^mro; # OUTPUT: «((CArray[int32]) (CArray) (Any) (Mu))␤»
>>
>> It does include a `list` for convenience, but it's not, by itself, a
>> list. That operator does not do the conversion, but expects it to be a
>> list, hence the error.
>>
>> Hope this helps
>>
>> JJ
>>
>

-- 
brandon s allbery kf8nh
allber...@gmail.com

Reply via email to