Class: Dhall::TypeChecker::Merge::AnnotatedMerge

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

Instance Method Summary collapse

Constructor Details

#initialize(merge:, record:, input:) ⇒ AnnotatedMerge

Returns a new instance of AnnotatedMerge.



807
808
809
810
811
812
813
814
815
816
817
# File 'lib/dhall/typecheck.rb', line 807

def initialize(merge:, record:, input:)
	@merge = merge.with(record: record, input: input)
	@handlers = Handlers.new(record)
	@record = record
	@union = input

	TypeChecker.assert @union.type, Dhall::UnionType,
	                   "Merge expected Union got: #{@union.type}"

	assert_union_and_handlers_match
end

Instance Method Details

#annotationObject



819
820
821
822
823
824
# File 'lib/dhall/typecheck.rb', line 819

def annotation
	Dhall::TypeAnnotation.new(
		value: @merge,
		type:  type
	)
end

#assert_kind(context) ⇒ Object



830
831
832
833
834
835
836
837
838
839
840
# File 'lib/dhall/typecheck.rb', line 830

def assert_kind(context)
	kind = TypeChecker.for(type).annotate(context).type

	TypeChecker.assert(
		kind,
		Builtins[:Type],
		"Merge must have kind Type"
	)

	kind
end

#assert_union_and_handlers_matchObject



842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'lib/dhall/typecheck.rb', line 842

def assert_union_and_handlers_match
	extras = @handlers.keys ^ @union.type.alternatives.keys
	TypeChecker.assert extras.to_a, [],
	                   "Merge handlers unknown alternatives: #{extras}"

	@union.type.alternatives.each do |k, atype|
		atype.nil? || TypeChecker.assert(
			@handlers.fetch_input_type(k),
			atype,
			"Handler argument does not match alternative type: #{atype}"
		)
	end
end

#typeObject



826
827
828
# File 'lib/dhall/typecheck.rb', line 826

def type
	@type ||= @handlers.output_type(@merge.type)
end