Class: MilkTea::ValidateSpecializedTypeVisitor

Inherits:
TypeVisitor
  • Object
show all
Defined in:
lib/milk_tea/core/types/visitor.rb

Instance Method Summary collapse

Methods inherited from TypeVisitor

#dispatch, #visit, #visit_children, #visit_default, #visit_dyn, #visit_event, #visit_generic_struct_definition, #visit_generic_variant_definition, #visit_lifetime_ref, #visit_null, #visit_nullable, #visit_parameter, #visit_soa, #visit_span, #visit_struct, #visit_struct_instance, #visit_task, #visit_tuple, #visit_union, #visit_variant, #visit_variant_arm_payload, #visit_variant_instance

Constructor Details

#initialize(function_name:, context:, on_error:, on_generic_instance: nil) ⇒ ValidateSpecializedTypeVisitor

Returns a new instance of ValidateSpecializedTypeVisitor.



395
396
397
398
399
400
401
# File 'lib/milk_tea/core/types/visitor.rb', line 395

def initialize(function_name:, context:, on_error:, on_generic_instance: nil)
  super()
  @function_name = function_name
  @context = context
  @on_error = on_error
  @on_generic_instance = on_generic_instance
end

Instance Method Details

#visit_function(type) ⇒ Object



419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/milk_tea/core/types/visitor.rb', line 419

def visit_function(type)
  type.params.each do |param|
    with_context("#{@context} parameter #{param.name}") { visit(param.type) }
    if param.boundary_type
      with_context("#{@context} boundary parameter #{param.name}") { visit(param.boundary_type) }
    end
  end
  with_context("#{@context} return type") { visit(type.return_type) }
  if type.receiver_type
    with_context("#{@context} receiver type") { visit(type.receiver_type) }
  end
end

#visit_generic_instance(type) ⇒ Object



407
408
409
410
# File 'lib/milk_tea/core/types/visitor.rb', line 407

def visit_generic_instance(type)
  @on_generic_instance&.call(type.name, type.arguments)
  visit_children(type)
end

#visit_proc(type) ⇒ Object



412
413
414
415
416
417
# File 'lib/milk_tea/core/types/visitor.rb', line 412

def visit_proc(type)
  type.params.each do |param|
    with_context("#{@context} parameter #{param.name}") { visit(param.type) }
  end
  with_context("#{@context} return type") { visit(type.return_type) }
end

#visit_type_var(type) ⇒ Object



403
404
405
# File 'lib/milk_tea/core/types/visitor.rb', line 403

def visit_type_var(type)
  @on_error.call("cannot infer type argument #{type.name} for function #{@function_name}")
end