Class: Steep::TypeInference::Context

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

Defined Under Namespace

Classes: BlockContext, BreakContext, MethodContext, ModuleContext, TypeVariableContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_context:, block_context:, break_context:, module_context:, self_type:, type_env:, call_context:, variable_context:) ⇒ Context

Returns a new instance of Context.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/steep/type_inference/context.rb', line 151

def initialize(method_context:, block_context:, break_context:, module_context:, self_type:, type_env:, call_context:, variable_context:)
  @method_context = method_context
  @block_context = block_context
  @break_context = break_context
  @module_context = module_context
  @self_type = self_type
  @type_env = type_env
  @call_context = call_context
  @variable_context = variable_context

  if self_type.free_variables.include?(AST::Types::Self.instance)
    raise "Context#self_type cannot contain `self`"
  end
end

Instance Attribute Details

#block_contextObject (readonly)

Returns the value of attribute block_context.



144
145
146
# File 'lib/steep/type_inference/context.rb', line 144

def block_context
  @block_context
end

#break_contextObject (readonly)

Returns the value of attribute break_context.



145
146
147
# File 'lib/steep/type_inference/context.rb', line 145

def break_context
  @break_context
end

#call_contextObject (readonly)

Returns the value of attribute call_context.



142
143
144
# File 'lib/steep/type_inference/context.rb', line 142

def call_context
  @call_context
end

#method_contextObject (readonly)

Returns the value of attribute method_context.



143
144
145
# File 'lib/steep/type_inference/context.rb', line 143

def method_context
  @method_context
end

#module_contextObject (readonly)

Returns the value of attribute module_context.



146
147
148
# File 'lib/steep/type_inference/context.rb', line 146

def module_context
  @module_context
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



147
148
149
# File 'lib/steep/type_inference/context.rb', line 147

def self_type
  @self_type
end

#type_envObject (readonly)

Returns the value of attribute type_env.



148
149
150
# File 'lib/steep/type_inference/context.rb', line 148

def type_env
  @type_env
end

#variable_contextObject (readonly)

Returns the value of attribute variable_context.



149
150
151
# File 'lib/steep/type_inference/context.rb', line 149

def variable_context
  @variable_context
end

Instance Method Details

#envObject



196
197
198
# File 'lib/steep/type_inference/context.rb', line 196

def env
  factory.env
end

#factoryObject



192
193
194
# File 'lib/steep/type_inference/context.rb', line 192

def factory
  type_env.constant_env.factory
end

#inspectObject



186
187
188
189
190
# File 'lib/steep/type_inference/context.rb', line 186

def inspect
  s = "#<%s:%#018x " % [self.class, object_id]
  s << instance_variables.map(&:to_s).sort.map {|name| "#{name}=..." }.join(", ")
  s + ">"
end

#with(method_context: self.method_context, block_context: self.block_context, break_context: self.break_context, module_context: self.module_context, self_type: self.self_type, type_env: self.type_env, call_context: self.call_context, variable_context: self.variable_context) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/steep/type_inference/context.rb', line 166

def with(method_context: self.method_context,
         block_context: self.block_context,
         break_context: self.break_context,
         module_context: self.module_context,
         self_type: self.self_type,
         type_env: self.type_env,
         call_context: self.call_context,
         variable_context: self.variable_context)
  self.class.new(
    method_context: method_context,
    block_context: block_context,
    break_context: break_context,
    module_context: module_context,
    self_type: self_type, # steep:ignore ArgumentTypeMismatch
    type_env: type_env,
    call_context: call_context,
    variable_context: variable_context
  )
end