Class: MilkTea::SemanticAnalyzer::GenericInterfaceBinding

Inherits:
Data
  • Object
show all
Defined in:
lib/milk_tea/core/semantic_analyzer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast

Returns:

  • (Object)

    the current value of ast



70
71
72
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70

def ast
  @ast
end

#methodsObject (readonly)

Returns the value of attribute methods

Returns:

  • (Object)

    the current value of methods



70
71
72
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70

def methods
  @methods
end

#module_nameObject (readonly)

Returns the value of attribute module_name

Returns:

  • (Object)

    the current value of module_name



70
71
72
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



70
71
72
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70

def name
  @name
end

#type_param_constraintsObject (readonly)

Returns the value of attribute type_param_constraints

Returns:

  • (Object)

    the current value of type_param_constraints



70
71
72
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70

def type_param_constraints
  @type_param_constraints
end

#type_paramsObject (readonly)

Returns the value of attribute type_params

Returns:

  • (Object)

    the current value of type_params



70
71
72
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70

def type_params
  @type_params
end

Instance Method Details

#instantiate(arguments) ⇒ Object

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 71

def instantiate(arguments)
  raise ArgumentError, "#{name} expects #{type_params.length} type arguments, got #{arguments.length}" unless arguments.length == type_params.length

  substitutions = type_params.zip(arguments).to_h
  substituted_methods = methods.transform_values do |method|
    InterfaceMethodBinding.new(
      name: method.name,
      params: method.params.map { |p| Types::Registry.parameter(p.name, Types.substitute_type_variables(p.type, substitutions)) },
      return_type: Types.substitute_type_variables(method.return_type, substitutions),
      kind: method.kind,
      async: method.async,
      ast: method.ast,
    )
  end

  InterfaceBinding.new(
    name:,
    methods: substituted_methods.freeze,
    ast:,
    module_name:,
    type_arguments: arguments.freeze,
  )
end