Class: Dhallish::Ast::UnionLiteral
- Inherits:
-
Object
- Object
- Dhallish::Ast::UnionLiteral
- Defined in:
- lib/ast.rb
Instance Attribute Summary collapse
-
#init_label ⇒ Object
Returns the value of attribute init_label.
-
#init_val ⇒ Object
Returns the value of attribute init_val.
-
#map ⇒ Object
map: label -> type, can be empty.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(map, init_label, init_val) ⇒ UnionLiteral
constructor
A new instance of UnionLiteral.
Constructor Details
#initialize(map, init_label, init_val) ⇒ UnionLiteral
Returns a new instance of UnionLiteral.
683 684 685 686 687 |
# File 'lib/ast.rb', line 683 def initialize(map, init_label, init_val) @map = map @init_label = init_label @init_val = init_val end |
Instance Attribute Details
#init_label ⇒ Object
Returns the value of attribute init_label.
679 680 681 |
# File 'lib/ast.rb', line 679 def init_label @init_label end |
#init_val ⇒ Object
Returns the value of attribute init_val.
680 681 682 |
# File 'lib/ast.rb', line 680 def init_val @init_val end |
#map ⇒ Object
map: label -> type, can be empty
678 679 680 |
# File 'lib/ast.rb', line 678 def map @map end |
#type ⇒ Object
Returns the value of attribute type.
681 682 683 |
# File 'lib/ast.rb', line 681 def type @type end |
Instance Method Details
#compute_type(ctx) ⇒ Object
689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/ast.rb', line 689 def compute_type(ctx) types = {} @map.keys.each { |key| node = @map[key] assert ("duplicate labels not allowed in union literals") { !types.include? key } type_type = node.compute_type(ctx) assert ("Type annotation in Union Literal not a type") { type_type.is_a? Types::Type } @map[key] = types[key] = type_type. } assert ("duplicate labels not allowed in union literals") { !types.include? @init_label } types[@init_label] = @init_val.compute_type(ctx) @type = Types::Union.new(types) @type end |