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

infix:<%> gives fewer divide-by-zero errors than does infix:</> in Rakudo #2125

Closed
p6rt opened this issue Aug 31, 2010 · 8 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 31, 2010

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

Searchable as RT77592$

@p6rt
Copy link
Author

p6rt commented Aug 31, 2010

From @masak

<alksentrs> rakudo​: say 1 % 0
<p6eval> rakudo f8e959​: OUTPUT«1␤»
<masak> alksentrs​: o.O
<masak> alksentrs​: that should be a 'div by zorro' error, if you ask me.
<alksentrs> rakudo​: say 0 % 0
<p6eval> rakudo f8e959​: OUTPUT«0␤»
<colomon> $x % $y == $x - floor($x / $y) * $y
<alksentrs> rakudo​: say 0 / 0
<p6eval> rakudo f8e959​: OUTPUT«Divide by zero␤ in 'infix​:<div>' [...]
<colomon> rakudo​: say floor(1/0).perl
<p6eval> rakudo f8e959​: OUTPUT«Inf␤»
<TimToady> rakudo​: say (0/0).WHAT
<p6eval> rakudo f8e959​: OUTPUT«Divide by zero␤ in 'infix​:<div>' [...]
<colomon> rakudo​: say floor(1/0) * 0
<p6eval> rakudo f8e959​: OUTPUT«NaN␤»
<colomon> okay, so that's not how it's being calculated...
<colomon> ah, just a call to pir​::mod
* masak submits $x % 0 rakudobug
* colomon hopes masak doesn't expect us to trap LHS of 0 on infix​:<%>
before calling into Parrot...
<masak> colomon​: I expect $x % 0 to die just as much as $x / 0 does.

@p6rt
Copy link
Author

p6rt commented Mar 16, 2014

From @ShimmerFairy

Properly fails now​:

  <lue> r​: say 1 % 0
  <camelia> rakudo-parrot a24091​: OUTPUT«Type check failed for return value; expected 'Int' but got 'Failure'␤ in sub infix​:<%> at gen/parrot/CORE.setting​:4490␤ in sub infix​:<%> at gen/parrot/CORE.setting​:4094␤ in block at /tmp/tmpfile​:1␤␤»
  <camelia> ..rakudo-moar a24091​: OUTPUT«Divide by zero using infix​:<%>␤ in block at src/gen/m-CORE.setting​:12450␤ in sub infix​:<%> at src/gen/m-CORE.setting​:4486␤ in sub infix​:<%> at src/gen/m-CORE.setting​:4090␤ in block at /tmp/tmpfile​:1␤␤»
  <camelia> ..rakudo-jvm a24091​: OUTPUT«Type check failed for return value; expected 'Int' but got 'Failure'␤ in sub infix​:<%> at gen/jvm/CORE.setting​:4486␤ in sub infix​:<%> at gen/jvm/CORE.setting​:4090␤ in block at /tmp/tmpfile​:1␤␤»

A test for this is in ../roast/S03-operators/arith.t, as well as similar tests for %% in ../roast/S03-operators/is-divisible-by.t. Can be closed unless more tests are desired.

@p6rt
Copy link
Author

p6rt commented Mar 16, 2014

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

@p6rt
Copy link
Author

p6rt commented Nov 23, 2014

From @usev6

As it was said before, infix​:<%> now gives the same divide-by-zero errors as infix​:</>.

In roast we currently only test with 'dies_ok' and 'eval_dies_ok'. On #perl6 it was pointed out by psch++ two days ago that we don't fail directly with X​::Numeric​::DivideByZero, but with X​::TypeCheck​::Return (or X​::Typecheck​::Assignment)​:

<psch> right
<psch> lazy rats or something i think
<psch> m​: my $y = 3; my $x = do { CATCH { default { say .perl } }; ($y / 0).Int }; say $x.WHAT
<camelia> rakudo-moar a75337​: OUTPUT«X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)␤(Any)␤»
<psch> that means the $y / 0 returns something non-Int-y, which throws differently, with DivideByZero as additional payload
<psch> that seems a bit convoluted
<psch> as in, i can't imagine a case where we get *just* X​::Numeric​::DivideByZero not wrapped in some X​::TypeCheck

On a related note​: 'say 0 / 0' fails differently than the other three​:

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 0 / 0 ).Int };'
X​::TypeCheck​::Assignment.new(symbol => "\$numerator", operation => "assignment", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 1 / 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 0 % 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => "infix​:<\%>")), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 1 % 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => "infix​:<\%>")), expected => Int)

IMHO that meets the requirements of this ticket. So I'd vote for "closable (maybe after tweaking the tests to reflect the typed exceptions)".

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 23, 2014

From @usev6

As it was said before, infix​:<%> now gives the same divide-by-zero errors as infix​:</>.

In roast we currently only test with 'dies_ok' and 'eval_dies_ok'. On #perl6 it was pointed out by psch++ two days ago that we don't fail directly with X​::Numeric​::DivideByZero, but with X​::TypeCheck​::Return (or X​::Typecheck​::Assignment)​:

<psch> right
<psch> lazy rats or something i think
<psch> m​: my $y = 3; my $x = do { CATCH { default { say .perl } }; ($y / 0).Int }; say $x.WHAT
<camelia> rakudo-moar a75337​: OUTPUT«X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)␤(Any)␤»
<psch> that means the $y / 0 returns something non-Int-y, which throws differently, with DivideByZero as additional payload
<psch> that seems a bit convoluted
<psch> as in, i can't imagine a case where we get *just* X​::Numeric​::DivideByZero not wrapped in some X​::TypeCheck

On a related note​: 'say 0 / 0' fails differently than the other three​:

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 0 / 0 ).Int };'
X​::TypeCheck​::Assignment.new(symbol => "\$numerator", operation => "assignment", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 1 / 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 0 % 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => "infix​:<\%>")), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 1 % 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => "infix​:<\%>")), expected => Int)

IMHO that meets the requirements of this ticket. So I'd vote for "closable (maybe after tweaking the tests to reflect the typed exceptions)".

@p6rt
Copy link
Author

p6rt commented Nov 23, 2014

From @lizmat

FWIW, I think almost *all* dies_ok and eval_dies_ok should be eradicated from roast. The generate way too many false positives. Should probably be all converted to throws_like.

Liz

On 23 Nov 2014, at 23​:10, Christian Bartolomaeus via RT <bugs-comment@​bugs6.perl.org> wrote​:

As it was said before, infix​:<%> now gives the same divide-by-zero errors as infix​:</>.

In roast we currently only test with 'dies_ok' and 'eval_dies_ok'. On #perl6 it was pointed out by psch++ two days ago that we don't fail directly with X​::Numeric​::DivideByZero, but with X​::TypeCheck​::Return (or X​::Typecheck​::Assignment)​:

<psch> right
<psch> lazy rats or something i think
<psch> m​: my $y = 3; my $x = do { CATCH { default { say .perl } }; ($y / 0).Int }; say $x.WHAT
<camelia> rakudo-moar a75337​: OUTPUT«X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)␤(Any)␤»
<psch> that means the $y / 0 returns something non-Int-y, which throws differently, with DivideByZero as additional payload
<psch> that seems a bit convoluted
<psch> as in, i can't imagine a case where we get *just* X​::Numeric​::DivideByZero not wrapped in some X​::TypeCheck

On a related note​: 'say 0 / 0' fails differently than the other three​:

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 0 / 0 ).Int };'
X​::TypeCheck​::Assignment.new(symbol => "\$numerator", operation => "assignment", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 1 / 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => Any)), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 0 % 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => "infix​:<\%>")), expected => Int)

$ perl6 -e 'my $x = do { CATCH { default { say .perl } }; ( 1 % 0 ).Int };'
X​::TypeCheck​::Return.new(operation => "returning", got => Failure.new(exception => X​::Numeric​::DivideByZero.new(using => "infix​:<\%>")), expected => Int)

IMHO that meets the requirements of this ticket. So I'd vote for "closable (maybe after tweaking the tests to reflect the typed exceptions)".

@p6rt
Copy link
Author

p6rt commented Nov 24, 2014

From @usev6

On Sun Nov 23 14​:32​:43 2014, elizabeth wrote​:

FWIW, I think almost *all* dies_ok and eval_dies_ok should be
eradicated from roast. The generate way too many false positives.
Should probably be all converted to throws_like.

Liz

Hah! On that note I went ahead and changed those 'dies_ok' and 'eval_dies_ok' to more specific tests -- see commit Raku/roast@d025d6c4a7

If the new tests are too specific (or if there are too many of them), please feel free to modify the tests or reopen the ticket. (Which I'm closing now.)

Christian

@p6rt
Copy link
Author

p6rt commented Nov 24, 2014

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

@p6rt p6rt closed this as completed Nov 24, 2014
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant