~singpolyma/dhall-ruby

0555a22c9b7ac433b9219e25895e67da118aa3fe — Stephen Paul Weber 5 years ago 287dfd1
Refactor Union typecheck
2 files changed, 6 insertions(+), 4 deletions(-)

M lib/dhall/ast.rb
M lib/dhall/typecheck.rb
M lib/dhall/ast.rb => lib/dhall/ast.rb +4 -0
@@ 613,6 613,10 @@ module Dhall
			self == other
		end

		def merge(other)
			with(alternatives: alternatives.merge(other.alternatives))
		end

		def fetch(k, default=nil)
			if (default || block_given?) && !alternatives.key?(k)
				return (default || yield)

M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +2 -4
@@ 620,10 620,8 @@ module Dhall
				annotated_value = @value.annotate(context)

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

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