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

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

Closed
janlelis opened this Issue Feb 7, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@janlelis

janlelis commented Feb 7, 2017

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>>

@enebo enebo added this to the JRuby 9.1.8.0 milestone Feb 9, 2017

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Feb 9, 2017

Member

I would guess our ported logic for type these type conversions just needs some updating.

try_convert appears to use a RespondToCallSite, which I would have expected to do the right thing if there's no respond_to? defined. There may be some missing or incorrect logic in there for checking the presence of respond_to?.

Rational() calls convert on Rational, which eventually tries to call our Java-level respondsTo on the BasicObject, which blindly tries to call respond_to?. It should use a RespondToCallSite as well.

I think @juliancheal is going to take a poke at this.

Member

headius commented Feb 9, 2017

I would guess our ported logic for type these type conversions just needs some updating.

try_convert appears to use a RespondToCallSite, which I would have expected to do the right thing if there's no respond_to? defined. There may be some missing or incorrect logic in there for checking the presence of respond_to?.

Rational() calls convert on Rational, which eventually tries to call our Java-level respondsTo on the BasicObject, which blindly tries to call respond_to?. It should use a RespondToCallSite as well.

I think @juliancheal is going to take a poke at this.

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Feb 9, 2017

Member

Oops, I had the wrong bug for @juliancheal...we asked him to look at #4483. However the two bugs are rather similar.

Member

headius commented Feb 9, 2017

Oops, I had the wrong bug for @juliancheal...we asked him to look at #4483. However the two bugs are rather similar.

kares added a commit to kares/jruby that referenced this issue Feb 17, 2017

check for Object before triggerring respond_to?(:to_r) check
... also added a caching respond_to? call-site (see #4484)

kares added a commit to kares/jruby that referenced this issue Feb 19, 2017

kares added a commit that referenced this issue Feb 19, 2017

check for Object before triggerring respond_to?(:to_r) check
... also added a caching respond_to? call-site (see #4484)
@kares

This comment has been minimized.

Show comment
Hide comment
@kares

kares Feb 19, 2017

Member

... adding an instanceof RubyObject check (in both places) resolved the compatibility issue

Member

kares commented Feb 19, 2017

... adding an instanceof RubyObject check (in both places) resolved the compatibility issue

@kares kares closed this Feb 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment