Class: Dhallish::Ast::TypeAnnotationNode
- Inherits:
-
Object
- Object
- Dhallish::Ast::TypeAnnotationNode
- Defined in:
- lib/ast.rb
Instance Attribute Summary collapse
-
#expr ⇒ Object
Returns the value of attribute expr.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(expr, type) ⇒ TypeAnnotationNode
constructor
A new instance of TypeAnnotationNode.
Constructor Details
#initialize(expr, type) ⇒ TypeAnnotationNode
Returns a new instance of TypeAnnotationNode.
356 357 358 359 |
# File 'lib/ast.rb', line 356 def initialize(expr, type) @expr = expr @type = type end |
Instance Attribute Details
#expr ⇒ Object
Returns the value of attribute expr.
354 355 356 |
# File 'lib/ast.rb', line 354 def expr @expr end |
#type ⇒ Object
Returns the value of attribute type.
355 356 357 |
# File 'lib/ast.rb', line 355 def type @type end |
Instance Method Details
#compute_type(ctx) ⇒ Object
361 362 363 364 365 366 367 368 |
# File 'lib/ast.rb', line 361 def compute_type(ctx) act_type = @expr.compute_type ctx type_type = @type.compute_type ctx assert ("Annotated expression not a type") { type_type.is_a? Types::Type } exp_type = type_type. assert ("Expression does not match annotated type. Actual: #{act_type}, expected: #{exp_type}") { Types::unification act_type, exp_type } exp_type end |
#evaluate(ctx) ⇒ Object
370 371 372 |
# File 'lib/ast.rb', line 370 def evaluate(ctx) @expr.evaluate ctx end |