Class: Steep::TypeInference::Context::TypeVariableContext

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/type_inference/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_params, parent_context: nil) ⇒ TypeVariableContext

Returns a new instance of TypeVariableContext.



112
113
114
115
116
117
118
119
120
121
# File 'lib/steep/type_inference/context.rb', line 112

def initialize(type_params, parent_context: nil)
  @type_params = type_params

  @table = {}
  table.merge!(parent_context.table) if parent_context

  type_params.each do |param|
    table[param.name] = param
  end
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



109
110
111
# File 'lib/steep/type_inference/context.rb', line 109

def table
  @table
end

#type_paramsObject (readonly)

Returns the value of attribute type_params.



110
111
112
# File 'lib/steep/type_inference/context.rb', line 110

def type_params
  @type_params
end

Class Method Details

.emptyObject



135
136
137
# File 'lib/steep/type_inference/context.rb', line 135

def self.empty
  new([])
end

Instance Method Details

#[](name) ⇒ Object



123
124
125
# File 'lib/steep/type_inference/context.rb', line 123

def [](name)
  table.fetch(name).upper_bound
end

#upper_boundsObject



127
128
129
130
131
132
133
# File 'lib/steep/type_inference/context.rb', line 127

def upper_bounds
  @upper_bounds ||= table.each_value.with_object({}) do |type_param, bounds| #$ Hash[Symbol, AST::Types::t]
    if type_param.upper_bound
      bounds[type_param.name] = type_param.upper_bound
    end
  end
end