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.



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

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.



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

def table
  @table
end

#type_paramsObject (readonly)

Returns the value of attribute type_params.



112
113
114
# File 'lib/steep/type_inference/context.rb', line 112

def type_params
  @type_params
end

Class Method Details

.emptyObject



137
138
139
# File 'lib/steep/type_inference/context.rb', line 137

def self.empty
  new([])
end

Instance Method Details

#[](name) ⇒ Object



125
126
127
# File 'lib/steep/type_inference/context.rb', line 125

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

#upper_boundsObject



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

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