Exception: RBS::RecursiveAncestorError
- Inherits:
-
DefinitionError
- Object
- StandardError
- BaseError
- DefinitionError
- RBS::RecursiveAncestorError
- Defined in:
- lib/rbs/errors.rb
Instance Attribute Summary collapse
-
#ancestors ⇒ Object
readonly
Returns the value of attribute ancestors.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ancestors:, location:) ⇒ RecursiveAncestorError
constructor
A new instance of RecursiveAncestorError.
Constructor Details
#initialize(ancestors:, location:) ⇒ RecursiveAncestorError
Returns a new instance of RecursiveAncestorError.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rbs/errors.rb', line 114 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
#ancestors ⇒ Object (readonly)
Returns the value of attribute ancestors.
111 112 113 |
# File 'lib/rbs/errors.rb', line 111 def ancestors @ancestors end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
112 113 114 |
# File 'lib/rbs/errors.rb', line 112 def location @location end |
Class Method Details
.check!(self_ancestor, ancestors:, location:) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rbs/errors.rb', line 134 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 |