Class: Dhall::TypeChecker::Union

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

Instance Method Summary collapse

Constructor Details

#initialize(union) ⇒ Union

Returns a new instance of Union.



635
636
637
638
# File 'lib/dhall/typecheck.rb', line 635

def initialize(union)
  @union = union
  @value = TypeChecker.for(union.value)
end

Instance Method Details

#annotate(context) ⇒ Object



640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# File 'lib/dhall/typecheck.rb', line 640

def annotate(context)
  annotated_value = @value.annotate(context)

  type = Dhall::UnionType.new(
    alternatives: { @union.tag => annotated_value.type }
  ).merge(@union.alternatives)

  # Annotate to sanity check
  TypeChecker.for(type).annotate(context)

  Dhall::TypeAnnotation.new(
    value: @union.with(value: annotated_value),
    type:  type
  )
end