String#<=> doesn't handle non-string arguments, but in MRI it does
------------------------------------------------------------------

                 Key: JRUBY-1722
                 URL: http://jira.codehaus.org/browse/JRUBY-1722
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
         Environment: JRuby 1.1b1, latest trunk, Ubuntu 7.10
            Reporter: Vladimir Sizikov
         Attachments: string_compare_nonstring.diff

Consider the following example:

{noformat} 

obj = Object.new

def obj.to_str() "" end
def obj.<=>(arg) 1  end

puts ("abc" <=> obj)
puts ("xyz" <=> obj)

{noformat} 

MRI 1.8.6, MRI 1.9, Rubinius, all prints
-1
-1

JRuby prints:
nil
nil

This causes one rubinius spec failure:

String#<=> compares its argument and self by calling <=> on obj and turning the 
result around if obj responds to to_str FAILED
Expected nil to equal -1
/opt/work/rubinius/spec/mini_rspec.rb:221:in `=='
/opt/work/rubinius/./spec/core/string/comparison_spec.rb:68:in `=='
/opt/work/rubinius/./spec/core/string/comparison_spec.rb:63:in `it'
/opt/work/rubinius/spec/mini_rspec.rb:414:in `it'
/opt/work/rubinius/./spec/core/string/comparison_spec.rb:63:in `it'
/opt/work/rubinius/./spec/core/string/comparison_spec.rb:63:in `describe'
/opt/work/rubinius/spec/mini_rspec.rb:410:in `describe'
/opt/work/rubinius/./spec/core/string/comparison_spec.rb:49:in `describe'
/opt/work/rubinius/./spec/core/string/comparison_spec.rb:49:in `load'
tmp/last_mspec.rb:13:in `load'
tmp/last_mspec.rb:1:in `each'
tmp/last_mspec.rb:7:in `each'

The proposed patch fixes the problem and the spec failure.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to