Class: Dhall::TypeChecker::Merge::AnnotatedMerge
- Inherits:
-
Object
- Object
- Dhall::TypeChecker::Merge::AnnotatedMerge
- Defined in:
- lib/dhall/typecheck.rb
Instance Method Summary collapse
- #annotation ⇒ Object
- #assert_kind(context) ⇒ Object
- #assert_union_and_handlers_match ⇒ Object
-
#initialize(merge:, record:, input:) ⇒ AnnotatedMerge
constructor
A new instance of AnnotatedMerge.
- #type ⇒ Object
Constructor Details
#initialize(merge:, record:, input:) ⇒ AnnotatedMerge
Returns a new instance of AnnotatedMerge.
767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/dhall/typecheck.rb', line 767 def initialize(merge:, record:, input:) @merge = merge.with(record: record, input: input) @handlers = Handlers.new(record) @record = record @union = input TypeChecker.assert @union.type, Dhall::UnionType, "Merge expected Union got: #{@union.type}" assert_union_and_handlers_match end |
Instance Method Details
#annotation ⇒ Object
779 780 781 782 783 784 |
# File 'lib/dhall/typecheck.rb', line 779 def annotation Dhall::TypeAnnotation.new( value: @merge, type: type ) end |
#assert_kind(context) ⇒ Object
790 791 792 793 794 795 796 797 798 799 800 |
# File 'lib/dhall/typecheck.rb', line 790 def assert_kind(context) kind = TypeChecker.for(type).annotate(context).type TypeChecker.assert( kind, Builtins[:Type], "Merge must have kind Type" ) kind end |
#assert_union_and_handlers_match ⇒ Object
802 803 804 805 806 807 808 809 810 811 812 813 814 |
# File 'lib/dhall/typecheck.rb', line 802 def assert_union_and_handlers_match extras = @handlers.keys - @union.type.alternatives.keys TypeChecker.assert extras, [], "Merge handlers unknown alternatives: #{extras}" @union.type.alternatives.each do |k, atype| atype.nil? || TypeChecker.assert( @handlers.fetch_input_type(k), atype, "Handler argument does not match alternative type: #{atype}" ) end end |
#type ⇒ Object
786 787 788 |
# File 'lib/dhall/typecheck.rb', line 786 def type @type ||= @handlers.output_type(@merge.type) end |