On 02/26/2014 02:48 AM, Will Coleda (via RT) wrote:
> # New Ticket Created by  Will Coleda 
> # Please include the string:  [perl #121326]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=121326 >
> 
> 
> Marked as a nom regression, there are todo'd tests
> in S03-operators/comparison.t
> 
> {
>     class Blue {
>         method Numeric() { 3; }
>     }
>     my $a = Blue.new;
> 
>     ok +$a == 3, '+$a == 3 (just checking)';
>     ok $a == 3, '$a == 3';
>     ok $a != 4, '$a != 4';
>     nok $a != 3, 'not true that $a != 3';
> 
>     lives_ok { $a < 5 }, '$a < 5 lives okay';
>     lives_ok { $a <= 5 }, '$a <= 5 lives okay';
>     lives_ok { $a > 5 }, '$a > 5 lives okay';
>     lives_ok { $a >= 5 }, '$a => 5 lives okay';
> }
> 
> the lives_ok tests die with:
> 
> # Cannot call 'Real'; none of these signatures match:
> # :(Mu:U \v: *%_)

I'd argue that the current behaviour is actually correct, and the tests
are wrong.

The background is that method Numeric might return a Complex, which
would be fine for addition, but not for comparison. Thus comparison
operators call .Real and not .Numeric, and there's no such method.

I understand the desire to provide just one method for coercion to a
numeric value, but I can't think of any efficient way to offer such an
API that would be compatible with potentially returning Complex.

Cheers,
Moritz

Reply via email to