~singpolyma/dhall-ruby

d4e314e9c507af6609b97789f06126bbb7550c00 — Stephen Paul Weber 2 years ago 8847b96
Refactor projection typecheck
1 files changed, 7 insertions(+), 8 deletions(-)

M lib/dhall/typecheck.rb
M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +7 -8
@@ 609,24 609,23 @@ module Dhall

			def initialize(projection)
				@selector = projection.selector.normalize
				@projection = projection
				@project_by_expression = projection
				@project_by_keys = Dhall::RecordProjection.for(
					@project_by_expression.record,
					@selector.keys
				)
			end

			def annotate(context)
				TypeChecker.assert @selector, Dhall::RecordType,
				                   "RecordProjectionByExpression on #{@selector.class}"

				projection = Dhall::RecordProjection.for(
					@projection.record,
					@selector.keys
				)

				TypeChecker.assert_type projection, @selector.normalize,
				TypeChecker.assert_type @project_by_keys, @selector,
				                        "Type doesn't match #{@selector}",
				                        context: context

				Dhall::TypeAnnotation.new(
					value: @projection,
					value: @project_by_expression,
					type:  @selector
				)
			end