Project

General

Profile

Actions

Bug #11385

closed

`==` with bidirectional/cyclic dependency

Bug #11385: `==` with bidirectional/cyclic dependency

Added by allenwq (Allen Wang) over 10 years ago. Updated over 10 years ago.

Status:
Rejected
Assignee:
Target version:
-
[ruby-core:70076]

Description

class Something attr_accessor :friend def initialize(friend) self.friend = friend end def ==(other) friend == other.friend end end a = Something.new([]) b = Something.new([a]) a.friend = [b] a == b 

The above code returns true on OS X and Linux, by right it should give me a exception of stack level too deep.

( And on windows I can see the expected exception )


Files

test.rb (226 Bytes) test.rb Code to recreate the bug allenwq (Allen Wang), 07/22/2015 02:50 AM

Related issues 1 (0 open1 closed)

Updated by nobu (Nobuyoshi Nakada) over 10 years ago Actions #1 [ruby-core:70078]

  • Description updated (diff)
  • Status changed from Open to Rejected

true is the expected result, and the same with x64-mswin64_120.

Updated by lowjoel (Joel Low) over 10 years ago Actions #2 [ruby-core:70079]

Hi Nakada-san:

D:\> ruby -v ruby 2.2.3p147 (2015-07-04 revision 51143) [x64-mswin64_120] D:\> ruby test.rb test.rb:8:in `==': stack level too deep (SystemStackError) from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:8:in `==' ... 2574 levels... from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:8:in `==' from test.rb:17:in `<main>' 

It seems to be a problem specific to Windows. The test suite passes (IIRC)

Updated by Eregon (Benoit Daloze) over 10 years ago Actions #3 [ruby-core:70082]

Should the result not be false instead?
These two instances each have a different @friend and it cannot be determined if they are equal so "false" seems a much safer answer.

Also, this seems inconsistent to how Comparable#== treat such cases:

class Something attr_accessor :friend def initialize(friend) self.friend = friend end include Comparable def <=>(other) friend <=> other end end a = Something.new([]) b = Something.new([a]) a.friend = [b] p a == b # false (and not true like above!) 

Updated by Hanmac (Hans Mackowiak) over 10 years ago Actions #4 [ruby-core:70083]

my version is "ruby 2.3.0dev (2015-07-21 trunk 51319) [x86_64-linux]"

and it does return true for me too

Updated by Eregon (Benoit Daloze) over 10 years ago Actions #6

  • Related to Bug #1448: [patch] Proper handling of recursive arrays added
Actions

Also available in: PDF Atom