Class: Stone::AST::FunctionTypeAnnotation
- Inherits:
-
Stone::AST
- Object
- Stone::AST
- Stone::AST::FunctionTypeAnnotation
- Defined in:
- lib/stone/ast/function_type_annotation.rb
Instance Attribute Summary collapse
-
#param_types ⇒ Object
readonly
Returns the value of attribute param_types.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
Attributes inherited from Stone::AST
Instance Method Summary collapse
-
#initialize(param_types, return_type) ⇒ FunctionTypeAnnotation
constructor
A new instance of FunctionTypeAnnotation.
- #to_s ⇒ Object
-
#to_type(registry) ⇒ Object
Convert to Stone::Type for type checking.
Constructor Details
#initialize(param_types, return_type) ⇒ FunctionTypeAnnotation
Returns a new instance of FunctionTypeAnnotation.
10 11 12 13 14 |
# File 'lib/stone/ast/function_type_annotation.rb', line 10 def initialize(param_types, return_type) @param_types = param_types @return_type = return_type @name = :function_type_annotation end |
Instance Attribute Details
#param_types ⇒ Object (readonly)
Returns the value of attribute param_types.
8 9 10 |
# File 'lib/stone/ast/function_type_annotation.rb', line 8 def param_types @param_types end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
8 9 10 |
# File 'lib/stone/ast/function_type_annotation.rb', line 8 def return_type @return_type end |
Instance Method Details
#to_s ⇒ Object
16 17 18 19 20 |
# File 'lib/stone/ast/function_type_annotation.rb', line 16 def to_s params = @param_types.map(&:to_s).join(", ") return_str = @return_type.is_a?(FunctionTypeAnnotation) ? "(#{@return_type})" : @return_type.to_s "(#{params}) -> #{return_str}" end |
#to_type(registry) ⇒ Object
Convert to Stone::Type for type checking
23 24 25 26 27 |
# File 'lib/stone/ast/function_type_annotation.rb', line 23 def to_type(registry) param_stone_types = @param_types.map { |t| t.to_type(registry) } return_stone_type = @return_type.to_type(registry) Stone::Type.function(param_types: param_stone_types, return_type: return_stone_type) end |