M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +6 -12
@@ 500,20 500,14 @@ module Dhall
TypeChecker.for(mtype).annotate(context).type
end
- if (bad = kinds.find { |t| !KINDS.include?(t) })
- raise TypeError, "AnonymousType field kind #{bad} "\
- "not one of #{KINDS}"
- end
+ TypeChecker.assert (kinds - KINDS), [],
+ "AnonymousType field kind not one of #{KINDS}"
- if (bad = kinds.find { |t| t != kinds.first })
- raise TypeError, "AnonymousType field kind #{bad} "\
- "does not match #{kinds.first}"
- end
+ TypeChecker.assert kinds, Util::ArrayAllTheSame,
+ "AnonymousType field kinds not all the same"
- Dhall::TypeAnnotation.new(
- value: @type,
- type: kinds.first || KINDS.first
- )
+ type = kinds.first || KINDS.first
+ Dhall::TypeAnnotation.new(value: @type, type: type)
end
end
M lib/dhall/util.rb => lib/dhall/util.rb +6 -0
@@ 35,6 35,12 @@ module Dhall
end
end
+ module ArrayAllTheSame
+ def self.===(other)
+ Array === other && other.all? { |x| x == other.first }
+ end
+ end
+
def self.match_results(xs=nil, ys=nil)
Array(xs).each_with_index.map do |r, idx|
yield r, ys[idx]