#752: description -> to_s infinite loop --------------------------------------+------------------------------------- Reporter: ryand-ruby@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Resolution: wontfix Keywords: | --------------------------------------+------------------------------------- Changes (by martinlagardette@…): * status: new => closed * resolution: => wontfix * milestone: => MacRuby 0.7 Old description:
I had a failing unit test that was causing an infinite stack trace. The code in question was:
{{{ class SimpleNodeData attr_accessor :name, :path, :image, :expandable, :selectable, :container
def initialize name = "Untitled", path = nil self.name = name self.path = path self.expandable = true self.selectable = true self.container = true end
def compare other if SimpleNodeData === other return name.compare other.name end return NSOrderedAscending end
alias :<=> :compare
def description "%@ - '%@' expandable: %@, selectable: %@, container: %@" % [super, name, expandable, selectable, container] end
alias :to_s :description end }}}
That last alias is the real problem... comment it out and everything works fine.
I believe the failing test line was:
{{{ assert child.representedObject.path, child.representedObject.description }}}
and the representedObject was a SimpleNodeData instance.
New description: I had a failing unit test that was causing an infinite stack trace. The code in question was: {{{ #!ruby class SimpleNodeData attr_accessor :name, :path, :image, :expandable, :selectable, :container def initialize name = "Untitled", path = nil self.name = name self.path = path self.expandable = true self.selectable = true self.container = true end def compare other if SimpleNodeData === other return name.compare other.name end return NSOrderedAscending end alias :<=> :compare def description "%@ - '%@' expandable: %@, selectable: %@, container: %@" % [super, name, expandable, selectable, container] end alias :to_s :description end }}} That last alias is the real problem... comment it out and everything works fine. I believe the failing test line was: {{{ assert child.representedObject.path, child.representedObject.description }}} and the representedObject was a SimpleNodeData instance. -- Comment: The problem is the following line: {{{ #!ruby alias :to_s :description }}} When the programmer calls `-description` on MacRuby classes, MacRuby actually calls `#to_s`. This is both syntaxic sugar and needed in some cases. This also means that aliasing to_s to description is not needed. The reason it crashes it because of the `super` call actually.[[BR]] When you try to print it, Obj-C will send `-description` on the `super` object, which will actually dispatched to `#to_s`, because that's how `-description` is implemented on it. Note that your code works well if you replace `super` by `self`, since `self` re-implements `-description`. But MacRuby's default `-description` aliases to `#to_s` :-) Closing this as won't fix :-) -- Ticket URL: <http://www.macruby.org/trac/ticket/752#comment:1> MacRuby <http://macruby.org/>