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

Difference in error behavior for Rational() #2566

Closed
dazuma opened this issue Jan 9, 2022 · 3 comments
Closed

Difference in error behavior for Rational() #2566

dazuma opened this issue Jan 9, 2022 · 3 comments
Assignees
Milestone

Comments

@dazuma
Copy link
Contributor

dazuma commented Jan 9, 2022

In MRI (2.7.5 and 3.1.0 tested):

Rational("")  # raises ArgumentError

In TruffleRuby 21.3.0:

Rational("")  # => (0/1)

It seems that the same applies to any non-numeric string.

@eregon
Copy link
Member

eregon commented Jan 10, 2022

Indeed, thanks for the report, @aardvark179 could you take a look?
It sounds like Rational() is not strict with strings for some reason (looks like we're using to_r for Strings which is not strict, seems that code comes from Rubinius).

@aardvark179 aardvark179 self-assigned this Jan 10, 2022
@aardvark179
Copy link
Contributor

We end up delegating Rational('') to Rational.convert('', 1), which then falls ''.to_r. That all seems entirely sensible, but ''.to_r does return 0/1 on both MRI and TruffleRuby.

I love it when two different routes to creating something return different results. :-)

@aardvark179 aardvark179 added this to the 22.1.0 milestone Jan 17, 2022
@aardvark179
Copy link
Contributor

aardvark179 commented Jan 17, 2022

This is now fixed on master (5fd59aa).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants