Skip to content

Including modules creates an infinite loop between methods #1088

Open

Description

@rmosolgo

Hi! I think RDoc sometimes wrongly infers module ancestry and then methods can have cyclical see references.

I encountered this error in the docs for GrpahQL-Ruby (fix: rmosolgo/graphql-ruby#4819) and I created this script to replicate it:

# rdoc_bug.rb
module DoSomething
  def self.generate_module
    Module.new do
      include DoSomethingExtra
    end
  end

  def do_something
    1 + 1
  end

  module DoSomethingExtra
    include DoSomething

    def do_something
      super + 1
    end
  end
end

For me, that script ends in "stack level too deep":

$ rdoc rdoc_bug.rb
Parsing sources...
100% [ 1/ 1]  rdoc_bug.rb

Generating Darkfish format into /Users/rmosolgo/code/graphql-ruby/doc...
uh-oh! RDoc had a problem:
stack level too deep

run with --debug for full backtrace

I was able to work around it, so this bug is not blocking me, but I thought I'd open it here in case its helpful to anyone else.

Activity

  1. tompng commented on Feb 7, 2026

    @tompng
    Member

    RDoc documents include inside Module.new do end. This is a bug.

    Module.new do
      include DoSomethingExtra # Should be ignored
    end

    This bug is fixed in RDoc::Parser::PrismRuby parser (enabled with RDOC_USE_PRISM_PARSER=1) so the problem is partially reduced.

    However, infinite loop can be still reproducible with the following code:

    module DoSomething
      module DoSomethingExtra
        include DoSomething
        def do_something; end
      end
      include DoSomethingExtra
    
      def do_something; end
    end rescue nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions