Complex() Kernel method does not consult an object's to_c method #4483

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

Comments

Projects
None yet
3 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

complex.rb:

o = Object.new
def o.to_c
  1i  
end

p Complex(o)

Expected Behavior

  • Should print: (0+1i)

Actual Behavior

  • Throws error:
TypeError: not a real
     rect at org/jruby/RubyComplex.java:356
  convert at org/jruby/RubyComplex.java:435
  Complex at org/jruby/RubyKernel.java:357
   <main> at complex.rb:6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment