Class: Dhallish::Ast::UnionType

Inherits:
Object
  • Object
show all
Defined in:
lib/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ UnionType



713
714
715
# File 'lib/ast.rb', line 713

def initialize(map)
	@map = map
end

Instance Attribute Details

#mapObject

map: maps labels to ast-nodes that should be types



711
712
713
# File 'lib/ast.rb', line 711

def map
  @map
end

Instance Method Details

#compute_type(ctx) ⇒ Object



717
718
719
720
721
722
723
724
725
726
# File 'lib/ast.rb', line 717

def compute_type(ctx)
	types_map = {}
	@map.each { |key, type|
		assert ("Duplicate labels in Union Types are not allowed") { !types_map.include? key }
		type_type = type.compute_type ctx
		assert ("annotated type in union type not a type") { type_type.is_a? Types::Type }
		types_map[key] = type_type.
	}
	Types::Type.new(Types::Union.new types_map)
end

#evaluate(ctx) ⇒ Object



728
729
730
731
732
733
734
# File 'lib/ast.rb', line 728

def evaluate(ctx)
	res = {}
	@map.each { |key, node|
		res[key] = node.evaluate ctx
	}
	Types::Union.new(res)
end