From a5631e2d452c66110d6dfb5197ad2cb0bb5cc543 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 29 Mar 2019 21:19:16 -0500 Subject: [PATCH] Refactor OperatorRecursiveRecordTypeMerge typecheck --- lib/dhall/typecheck.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/dhall/typecheck.rb b/lib/dhall/typecheck.rb index 0a1d893..6c033fa 100644 --- a/lib/dhall/typecheck.rb +++ b/lib/dhall/typecheck.rb @@ -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 -- 2.45.2