···55 # TODO: We can generate this and make it much more extensive.
66 METHOD_TYPE_MAPPINGS = {
77 :call => Set[Proc, Method],
88- :to_proc => Set[Proc, Method],
88+ :to_proc => Set[Proc, Method, Symbol],
99 :to_s => Set[String],
1010 }.freeze
1111
+4-11
lib/literal/types/union_type.rb
···2233class Literal::Types::UnionType
44 include Enumerable
55+ include Literal::Type
5667 def initialize(*queue)
78 raise Literal::ArgumentError.new("_Union type must have at least one type.") if queue.size < 1
···3233 attr_reader :types, :primitives
33343435 def inspect
3535- "_Union(#{@types.inspect})"
3636+ "_Union(#{to_a.map(&:inspect).join(', ')})"
3637 end
37383839 def ===(value)
···6667 self[key] or raise KeyError.new("Key not found: #{key.inspect}")
6768 end
68696969- def record_literal_type_errors(ctx)
7070- each do |type|
7171- ctx.add_child(label: type.inspect, expected: type, actual: ctx.actual)
7272- end
7373-7474- ctx.children.clear if ctx.children.none? { |c| c.children.any? }
7575- end
7676-7770 def >=(other)
7871 types = @types
7972 primitives = @primitives
···8174 case other
8275 when Literal::Types::UnionType
8376 types_have_at_least_one_subtype = other.types.all? do |other_type|
8484- primitives.any? { |p| Literal.subtype?(p, of: other_type) } || types.any? { |t| Literal.subtype?(t, of: other_type) }
7777+ primitives.any? { |p| Literal.subtype?(other_type, of: p) } || types.any? { |t| Literal.subtype?(other_type, of: t) }
8578 end
86798780 primitives_have_at_least_one_subtype = other.primitives.all? do |other_primitive|
8888- primitives.any? { |p| Literal.subtype?(p, of: other_primitive) } || types.any? { |t| Literal.subtype?(t, of: other_primitive) }
8181+ primitives.any? { |p| Literal.subtype?(other_primitive, of: p) } || types.any? { |t| Literal.subtype?(other_primitive, of: t) }
8982 end
90839184 types_have_at_least_one_subtype && primitives_have_at_least_one_subtype