Project

General

Profile

Actions

Bug #3420

closed

Module#method calling <=> causes SystemStackError

Bug #3420: Module#method calling <=> causes SystemStackError

Added by boof (Florian Aßmann) over 15 years ago. Updated over 14 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
1.9.2-head
Backport:
[ruby-core:30707]

Description

=begin
It seems the SystemStackError will be raised when compar.c calls the spaceship:

 static VALUE cmp_eq(VALUE *a) { VALUE c = rb_funcall(a[0], cmp, 1, a[1]); ... ruby-1.9.2-head > BrokenComparable = Module.new { def ==(other) self <=> other end } BrokenClass = Class.new { include BrokenComparable } BrokenClass.new == nil SystemStackError: stack level too deep 

The current implementation of the spaceship operator ...

 static VALUE rb_mod_cmp(VALUE mod, VALUE arg) { *snip* cmp = rb_class_inherited_p(mod, arg); ... 

... imho tries to lookup the method in the parent classes but fails because
it's actually implemented in the Kernel module:

 ruby-1.9.2-head > Object.instance_methods(false) => [] ruby-1.9.2-head > Object.superclass.instance_methods(false) => [:==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__] ruby-1.9.2-head > Object.superclass.superclass.methods(false) => [] ruby-1.9.2-head > Object.superclass.superclass.class.instance_methods(false) => [:to_i, :to_f, :to_s, :to_a, :inspect, :&, :|, :^, :nil?, :to_r, :rationalize, :to_c] ruby-1.9.2-head > Object.superclass.superclass.class.superclass.instance_methods(false) => [] ruby-1.9.2-head > Object.superclass.superclass.class.superclass.superclass.instance_methods(false) => [:==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__] ... ruby-1.9.2-head > Kernel.instance_methods(false) => [:nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :__id__, :object_id, :to_enum, :enum_for] 

But I'm neither familiar with C nor the ruby source so this is just a guess.

For reference http://github.com/rails/rails/commit/0042f4166f783085eb909d69d542b5323d8af5d6#commitcomment-91341.

Regards
Florian Aßmann
=end

Actions

Also available in: PDF Atom