~singpolyma/dhall-ruby

21c688d4f96f6f268c83a55f49073b5d611570d8 — Stephen Paul Weber 3 years ago 45f1846
Update to new UnionType selection semantics
2 files changed, 14 insertions(+), 4 deletions(-)

M lib/dhall/ast.rb
M lib/dhall/normalize.rb
M lib/dhall/ast.rb => lib/dhall/ast.rb +12 -3
@@ 607,6 607,16 @@ module Dhall
			selector ::String
		end)

		def call(value)
			if record.is_a?(UnionType)
				type = record.alternatives.fetch(selector)
				body = Union.from(record, selector, Variable[selector])
				Function.new(var: selector, type: type, body: body).call(value)
			else
				super
			end
		end

		def as_json
			[9, record.as_json, selector]
		end


@@ 659,9 669,8 @@ module Dhall
		end

		def fetch(k, default=nil)
			if (type = alternatives.fetch(k))
				body = Union.from(self, k, Variable[k])
				Function.new(var: k, type: type, body: body).normalize
			if alternatives.fetch(k)
				super(k)
			else
				Union.from(self, k, nil)
			end

M lib/dhall/normalize.rb => lib/dhall/normalize.rb +2 -1
@@ 52,7 52,8 @@ module Dhall
			return normalized.fuse if normalized.fuse

			if normalized.function.is_a?(Builtin) ||
			   normalized.function.is_a?(Function)
			   normalized.function.is_a?(Function) ||
			   normalized.function.is_a?(RecordSelection)
				return normalized.function.call(normalized.argument)
			end