Class: RBS::Environment::MultiEntry
- Inherits:
-
Object
- Object
- RBS::Environment::MultiEntry
- Defined in:
- lib/rbs/environment.rb
Direct Known Subclasses
Constant Summary collapse
- D =
_ = Struct.new(:decl, :outer, keyword_init: true) do # @implements D[M] include ContextUtil def context @context ||= calculate_context(outer + [decl]) end end
Instance Attribute Summary collapse
-
#decls ⇒ Object
readonly
Returns the value of attribute decls.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #compatible_params?(ps1, ps2) ⇒ Boolean
-
#initialize(name:) ⇒ MultiEntry
constructor
A new instance of MultiEntry.
- #insert(decl:, outer:) ⇒ Object
- #primary ⇒ Object
- #type_params ⇒ Object
- #validate_type_params ⇒ Object
Constructor Details
#initialize(name:) ⇒ MultiEntry
Returns a new instance of MultiEntry.
34 35 36 37 |
# File 'lib/rbs/environment.rb', line 34 def initialize(name:) @name = name @decls = [] end |
Instance Attribute Details
#decls ⇒ Object (readonly)
Returns the value of attribute decls.
32 33 34 |
# File 'lib/rbs/environment.rb', line 32 def decls @decls end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/rbs/environment.rb', line 31 def name @name end |
Instance Method Details
#compatible_params?(ps1, ps2) ⇒ Boolean
61 62 63 64 65 |
# File 'lib/rbs/environment.rb', line 61 def compatible_params?(ps1, ps2) if ps1.size == ps2.size ps1 == AST::TypeParam.rename(ps2, new_names: ps1.map(&:name)) end end |
#insert(decl:, outer:) ⇒ Object
39 40 41 42 |
# File 'lib/rbs/environment.rb', line 39 def insert(decl:, outer:) decls << D.new(decl: decl, outer: outer) @primary = nil end |
#primary ⇒ Object
71 72 73 |
# File 'lib/rbs/environment.rb', line 71 def primary raise "Not implemented" end |
#type_params ⇒ Object
67 68 69 |
# File 'lib/rbs/environment.rb', line 67 def type_params primary.decl.type_params end |
#validate_type_params ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rbs/environment.rb', line 44 def validate_type_params unless decls.empty? hd_decl, *tl_decls = decls raise unless hd_decl hd_params = hd_decl.decl.type_params tl_decls.each do |tl_decl| tl_params = tl_decl.decl.type_params unless compatible_params?(hd_params, tl_params) raise GenericParameterMismatchError.new(name: name, decl: _ = tl_decl.decl) end end end end |