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

Remove senseless spec. #1140

Merged
merged 1 commit into from
Mar 11, 2024
Merged

Remove senseless spec. #1140

merged 1 commit into from
Mar 11, 2024

Conversation

marcandre
Copy link
Member

@marcandre marcandre commented Mar 5, 2024

A negative size makes no sense at all, -infinity even less so. It is indeed the case that Ruby currently returns -infinity (even if you take the product of two of these senseless enumerables), but that doesn't make it a valid spec. Ruby does this because it is simpler to test for ±infinity than it is to test for +infinity...

Other alternative implementations should not attempt to mimick such behaviour.

One could argue it is a bug (and nil should be returned maybe, but that would be the case for any negative size), or that the current result is acceptable because "garbage in garbage out", but nobody in their right mind would rely on this behavior and clearly returning nil or raising an exception are better results than returning - infinity.

This PR leaves this uninteresting and ill-defined corner case as implementation dependent.

Ref: marcandre/backports#192

marcandre added a commit to headius/backports that referenced this pull request Mar 5, 2024
Let's not go out of our way to return senseless results.
See ruby/spec#1140
A negative `size` makes no sense at all, -infinity even less so. It is indeed the case that Ruby currently returns `-infinity` (even if you take the product of two of these senseless enumerables), but that doesn't make it a _valid spec_. Ruby does this because it is simpler to test for ±infinity than it is to test for +infinity...

Other alternative implementations should _not_ attempt to mimick such behaviour.

One could argue it is a bug (and `nil` should be returned maybe, but that would be the case for any negative `size`), or that the current result is acceptable because  "garbage in garbage out", but nobody in their right mind would rely on this behavior and clearly returning `nil` or raising an exception are better results than returning - infinity.

This PR leaves this uninteresting and ill-defined corner case as implementation dependent.
@andrykonchin
Copy link
Member

Agree!

Wondering if it makes sense to have means to specify explicitly in specs that some case has undefined behaviour or implementation-specific one? In case a CRuby behaviour is considered as not accurate?

@andrykonchin andrykonchin merged commit f23d158 into master Mar 11, 2024
26 checks passed
@andrykonchin andrykonchin deleted the remove_senseless_spec branch March 11, 2024 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants