Skip to content

Rational() and IO.try_convert do not work for BasicObjects #4484

@janlelis

Description

@janlelis

Environment

  • ruby -v jruby 9.1.8.0-SNAPSHOT (2.3.1) 2017-02-06 3f97c7a Java HotSpot(TM) 64-Bit Server VM 25.111-b14 on 1.8.0_111-b14 +indy +jit [linux-x86_64]
  • uname -a Linux ok 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Test Case

o = BasicObject.new

begin
  p IO.try_convert(o)
rescue
  p $!
end

begin
  p Rational(o)
rescue
  p $!
end

Expected Behavior

  • MRI returns nil for the try_convert case, and raises a TypeError for Rational(). If conversion would be possible (to_io or to_r exist), it would properly convert
nil
#<TypeError: can't convert BasicObject into Rational>

Actual Behavior

  • JRuby always raises NoMethodErrors (no matter if to_io or to_r exist):
#<NoMethodError: undefined method `respond_to?' for #<BasicObject:0x6ec8211c>>
#<NoMethodError: undefined method `respond_to?' for #<BasicObject:0x6ec8211c>>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions