[ruby-core:78029] [Ruby trunk Bug#12907] rb_respond_to() return value is incorrect

From: peter@...
Date: 2016-11-07 04:24:07 UTC
List: ruby-core #78029
Issue #12907 has been reported by Peter Ohler.

----------------------------------------
Bug #12907: rb_respond_to() return value is incorrect
https://bugs.ruby-lang.org/issues/12907

* Author: Peter Ohler
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.0, 2.3.1
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
As of Ruby 2.3.0 rb_respond_to incorrectly reports non-zero for methods that are not supported. This occurs with subclasses of BasicObject. This occurs with Oj when but should occur with other C code. A simple sample that demonstrates the failure in below. It works fine on all versions of Ruby until 2.3.0.

    require 'oj'
    
    class A < BasicObject
      def initialize(data)
        @data = data
      end
    end
    
    a = A.new("xyz")
    
    json = Oj.dump(a, mode: :compat, use_to_json: true)
    #=> NoMethodError: undefined method `to_hash' for #<A:0x007fae03de1dc8>

In the C code the rb_respond_to() function is called to determine if an instance of A responds to "to_hash". 1 is returned in Ruby 2.3.x while previous versions correctly returned 0.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next