~singpolyma/dhall-ruby

a5631e2d452c66110d6dfb5197ad2cb0bb5cc543 — Stephen Paul Weber 5 years ago 7710663
Refactor OperatorRecursiveRecordTypeMerge typecheck
1 files changed, 8 insertions(+), 13 deletions(-)

M lib/dhall/typecheck.rb
M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +8 -13
@@ 361,27 361,22 @@ module Dhall
			end

			def annotate(context)
				annotated_lhs = @lhs.annotate(context)
				annotated_rhs = @rhs.annotate(context)
				lhs_kind = @lhs.annotate(context).type
				rhs_kind = @rhs.annotate(context).type

				if annotated_lhs.type != annotated_rhs.type
					raise TypeError, "RecursiveRecordTypeMerge mixed kinds: " \
					                 "#{annotated_lhs.type}, #{annotated_rhs.type}"
				end
				TypeChecker.assert lhs_kind, rhs_kind,
				                   "RecursiveRecordTypeMerge mixed kinds: " \
				                   "#{lhs_kind}, #{rhs_kind}"

				type = @expr.lhs.deep_merge_type(@expr.rhs)

				unless type.is_a?(Dhall::RecordType)
					raise TypeError, "RecursiveRecordMerge got #{type}"
				end
				TypeChecker.assert type, Dhall::RecordType,
				                   "RecursiveRecordMerge got #{type}"

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

				Dhall::TypeAnnotation.new(
					value: @expr,
					type:  annotated_lhs.type
				)
				Dhall::TypeAnnotation.new(value: @expr, type: lhs_kind)
			end
		end