123456789_123456789_123456789_123456789_123456789_

Class: RBS::Environment::MultiEntry

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/rbs/environment.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name:) ⇒ MultiEntry

[ GitHub ]

  
# File 'lib/rbs/environment.rb', line 36

def initialize(name:)
  @name = name
  @decls = []
end

Instance Attribute Details

#decls (readonly)

[ GitHub ]

  
# File 'lib/rbs/environment.rb', line 34

attr_reader :decls

#name (readonly)

[ GitHub ]

  
# File 'lib/rbs/environment.rb', line 33

attr_reader :name

Instance Method Details

#compatible_params?(ps1, ps2) ⇒ Boolean

[ GitHub ]

  
# File 'lib/rbs/environment.rb', line 63

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:)

[ GitHub ]

  
# File 'lib/rbs/environment.rb', line 41

def insert(decl:, outer:)
  decls << D.new(decl: decl, outer: outer)
  @primary = nil
end

#primary

[ GitHub ]

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

def primary
  raise "Not implemented"
end

#type_params

[ GitHub ]

  
# File 'lib/rbs/environment.rb', line 69

def type_params
  primary.decl.type_params
end

#validate_type_params

[ GitHub ]

  
# File 'lib/rbs/environment.rb', line 46

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