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

Enumerable#sort_by raises wrong error for incomparable items #1113

Closed
headius opened this issue Oct 10, 2013 · 2 comments
Closed

Enumerable#sort_by raises wrong error for incomparable items #1113

headius opened this issue Oct 10, 2013 · 2 comments
Assignees
Labels

Comments

@headius
Copy link
Member

headius commented Oct 10, 2013

For #1105 I explored the logic for when elements in an Enumerable do not compare. On both JRuby and MRI, this results in an error, but the error is different: JRuby raises TypeError (trying to convert the false comparable result to an int) and MRI raises ArgumentError.

It's a minor difference, but it should be fixed.

$ jruby -e "[5,4,3,2,1,0].sort_by {|i| next nil if i == 3; i}"
TypeError: no implicit conversion from nil to integer
  sort_by at org/jruby/RubyEnumerable.java:479
   (root) at -e:1

$ rvm ruby-head do ruby -e "[5,4,3,2,1,0].sort_by {|i| next nil if i == 3; i}"
-e:1:in `sort_by': comparison of NilClass with 2 failed (ArgumentError)
    from -e:1:in `<main>'
@BanzaiMan
Copy link
Member

Not sure why, but it's failing on Travis only on Java 7. https://travis-ci.org/jruby/jruby/builds/12506221 https://travis-ci.org/jruby/jruby/jobs/12506222#L700

The spec passes locally.

@BanzaiMan BanzaiMan reopened this Oct 14, 2013
@ghost ghost assigned headius Oct 14, 2013
@enebo enebo modified the milestone: JRuby 9.0.0.0 Jul 14, 2015
@kares
Copy link
Member

kares commented Apr 8, 2016

both 1.7.24 and 9.0.5 now behave as expected :

ArgumentError: comparison of NilClass with 4 failed
  sort_by at org/jruby/RubyEnumerable.java:525
    <top> at -e:1

@kares kares closed this as completed Apr 8, 2016
@kares kares added this to the Invalid or Duplicate milestone Apr 8, 2016
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

4 participants