Project

General

Profile

Actions

Bug #8055

closed

Method with the same name as accessor causes stack level too deep error

Added by firedev (Nick O) almost 12 years ago. Updated almost 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
1.9.3
Backport:
[ruby-core:53259]

Description

To me this looks like a bug. It causes stack level too deep in all versions of Ruby (1.9 and 2.0 at least).

class Test
attr_accessor :uuid
def uuid
self.uuid ||=1
end
end

Test.new.uuid
SystemStackError: stack level too deep
from /Users/pain/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!

Updated by duerst (Martin Dürst) almost 12 years ago

  • Status changed from Open to Rejected

An accessor is just a method. If you then use def to define a method with the same name, the accessor gets overwritten. You end up with a recursive method, which will blow up the stack. You can do that even quicker:

def a
a
end

a
SystemStackError: stack level too deep

Actions

Also available in: Atom PDF

Like0
Like0