Exception: RBS::RecursiveAncestorError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rbs/errors.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ancestors:, location:) ⇒ RecursiveAncestorError

Returns a new instance of RecursiveAncestorError.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rbs/errors.rb', line 42

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

Instance Attribute Details

#ancestorsObject (readonly)

Returns the value of attribute ancestors.



39
40
41
# File 'lib/rbs/errors.rb', line 39

def ancestors
  @ancestors
end

#locationObject (readonly)

Returns the value of attribute location.



40
41
42
# File 'lib/rbs/errors.rb', line 40

def location
  @location
end

Class Method Details

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



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rbs/errors.rb', line 62

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