class Dhallish::Ast::UnionLiteral

Attributes

init_label[RW]
init_val[RW]
map[RW]

map: label -> type, can be empty

type[RW]

Public Class Methods

new(map, init_label, init_val) click to toggle source
# File lib/ast.rb, line 683
def initialize(map, init_label, init_val)
        @map = map
        @init_label = init_label
        @init_val = init_val
end

Public Instance Methods

compute_type(ctx) click to toggle source
# 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.metadata
        }
        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
evaluate(ctx) click to toggle source
# File lib/ast.rb, line 704
def evaluate(ctx)
        Union.new @init_label, @init_val.evaluate(ctx), @type
end