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

comparison numerically with non-numeric fails #3347

Closed
p6rt opened this issue Feb 26, 2014 · 5 comments
Closed

comparison numerically with non-numeric fails #3347

p6rt opened this issue Feb 26, 2014 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Feb 26, 2014

Migrated from rt.perl.org#121326 (status was 'resolved')

Searchable as RT121326$

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

From @coke

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​: *%_)

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

From @moritz

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

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

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

From @moritz

On Tue Feb 25 17​:48​:37 2014, coke wrote​:

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​: *%_)

Tests fixed and unfudged.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Feb 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant