From 0555a22c9b7ac433b9219e25895e67da118aa3fe Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 29 Mar 2019 19:57:21 -0500 Subject: [PATCH] Refactor Union typecheck --- lib/dhall/ast.rb | 4 ++++ lib/dhall/typecheck.rb | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/dhall/ast.rb b/lib/dhall/ast.rb index 0057bae..551ab6f 100644 --- a/lib/dhall/ast.rb +++ b/lib/dhall/ast.rb @@ -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) diff --git a/lib/dhall/typecheck.rb b/lib/dhall/typecheck.rb index aa1a624..0193495 100644 --- a/lib/dhall/typecheck.rb +++ b/lib/dhall/typecheck.rb @@ -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) -- 2.45.2