Class: MilkTea::SemanticAnalyzer::GenericInterfaceBinding
- Inherits:
-
Data
- Object
- Data
- MilkTea::SemanticAnalyzer::GenericInterfaceBinding
- Defined in:
- lib/milk_tea/core/semantic_analyzer.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type_param_constraints ⇒ Object
readonly
Returns the value of attribute type_param_constraints.
-
#type_params ⇒ Object
readonly
Returns the value of attribute type_params.
Instance Method Summary collapse
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast
70 71 72 |
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70 def ast @ast end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods
70 71 72 |
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70 def methods @methods end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name
70 71 72 |
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70 def module_name @module_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name
70 71 72 |
# File 'lib/milk_tea/core/semantic_analyzer.rb', line 70 def name @name end |
#type_param_constraints ⇒ Object (readonly)
Returns the value of attribute 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_params ⇒ Object (readonly)
Returns the value of attribute 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
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 |