You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f Java HotSpot(TM) 64-Bit Server VM 25.91-b14 on 1.8.0_91-b14 +jit [darwin-x86_64]
Darwin 15.5.0 Darwin Kernel Version 15.5.0:
Expected Behavior
The '<' comparison operation should return true for any inputs (contrived example) for both classes.
This is the behavior seen in CRuby.
StringSubclass Is a<b? true
StringSubclass Is b<c? true
StringSubclass Is b<a? true
NotStringSubclass Is a<b? true
NotStringSubclass Is b<c? true
NotStringSubclass Is b<a? true
class StringSubclass < String
include Comparable
def <=>(input)
#puts "JRuby Never executes this code."
return -1;
end
end
class NotStringSubclass
include Comparable
def initialize(str)
@str = str
end
def <=>(input)
#puts "JRuby Executes this code since there is no superclass."
return -1;
end
end
puts "StringSubclass Is a<b? " + (StringSubclass.new("a")<StringSubclass.new("b")).to_s
puts "StringSubclass Is b<c? " + (StringSubclass.new("b")<StringSubclass.new("c")).to_s
puts "StringSubclass Is b<a? " + (StringSubclass.new("b")<StringSubclass.new("a")).to_s
puts "NotStringSubclass Is a<b? " + (NotStringSubclass.new("a")<NotStringSubclass.new("b")).to_s
puts "NotStringSubclass Is b<c? " + (NotStringSubclass.new("b")<NotStringSubclass.new("c")).to_s
puts "NotStringSubclass Is b<a? " + (NotStringSubclass.new("b")<NotStringSubclass.new("a")).to_s
Actual Behavior
Instead, the '<' comparison operation returns true/false based on the String class implementation of the mixin function for StringSubclass. NotStringSubclass still behaves as expected.
StringSubclass Is a<b? true
StringSubclass Is b<c? true
StringSubclass Is b<a? false
NotStringSubclass Is a<b? true
NotStringSubclass Is b<c? true
NotStringSubclass Is b<a? true
The text was updated successfully, but these errors were encountered:
manigandan-rajasekar
changed the title
Overriden mixin never being called
Superclass mixin implementation called instead of subclass implementation
Jun 22, 2016
This is because our String#< and most of the other comparable methods are hardcoded to use the base impl always. We either overstepped on this optimization or MRI backpedaled on it. In any case, we should fix this.
I can confirm MRI does not implement the various Comparable methods directly on String, and just lets them delegate to the re-dispatching impls. We can do that in the short term, but I'd like to still have fast guarded logic in place to skip the dispatch when possible.
Environment
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f Java HotSpot(TM) 64-Bit Server VM 25.91-b14 on 1.8.0_91-b14 +jit [darwin-x86_64]
Darwin 15.5.0 Darwin Kernel Version 15.5.0:
Expected Behavior
The '<' comparison operation should return true for any inputs (contrived example) for both classes.
This is the behavior seen in CRuby.
Actual Behavior
Instead, the '<' comparison operation returns true/false based on the String class implementation of the mixin function for StringSubclass. NotStringSubclass still behaves as expected.
The text was updated successfully, but these errors were encountered: