123456789_123456789_123456789_123456789_123456789_

Exception: RBS::RecursiveAncestorError

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, DefinitionError, BaseError, StandardError
Instance Chain:
self, DefinitionError, BaseError, StandardError
Inherits: RBS::DefinitionError
Defined in: lib/rbs/errors.rb

Class Method Summary

Instance Attribute Summary

Constructor Details

.new(ancestors:, location:) ⇒ RecursiveAncestorError

[ GitHub ]

  
# File 'lib/rbs/errors.rb', line 76

def initialize(ancestors:, location:)
  @ancestors = ancestors
  @location = location

  names = ancestors.map do |ancestor|
    case ancestor
    when Definition::Ancestor::Singleton
      "singleton(#{ancestor.name})"
    when Definition::Ancestor::Instance
      if ancestor.args.empty?
        ancestor.name.to_s
      else
        "#{ancestor.name}[#{ancestor.args.join(", ")}]"
      end
    end
  end

  super "#{Location.to_string location}: Detected recursive ancestors: #{names.join(" < ")}"
end

Class Method Details

.check!(self_ancestor, ancestors:, location:)

[ GitHub ]

  
# File 'lib/rbs/errors.rb', line 96

def self.check!(self_ancestor, ancestors:, location:)
  case self_ancestor
  when Definition::Ancestor::Instance
    if ancestors.any? {|a| a.is_a?(Definition::Ancestor::Instance) && a.name == self_ancestor.name }
      raise new(ancestors: ancestors + [self_ancestor], location: location)
    end
  when Definition::Ancestor::Singleton
    if ancestors.include?(self_ancestor)
      raise new(ancestors: ancestors + [self_ancestor], location: location)
    end
  end
end

Instance Attribute Details

#ancestors (readonly)

[ GitHub ]

  
# File 'lib/rbs/errors.rb', line 73

attr_reader :ancestors

#location (readonly)

[ GitHub ]

  
# File 'lib/rbs/errors.rb', line 74

attr_reader :location