···284284 refute _Tuple(String, Integer) === nil
285285end
286286287287-test "_Union" do
288288- type = _Union(String, Integer)
287287+describe "_Union" do
288288+ test "_Union" do
289289+ type = _Union(String, Integer)
290290+291291+ assert type === "string"
292292+ assert type === 42
293293+294294+ refute type === :symbol
295295+ refute type === []
296296+ refute type === nil
297297+ end
289298290290- assert type === "string"
291291- assert type === 42
299299+ test "flattens types" do
300300+ type = _Union(
301301+ _Union(String, Integer),
302302+ _Union(Symbol, Float),
303303+ )
292304293293- refute type === :symbol
294294- refute type === []
295295- refute type === nil
305305+ expect(type.inspect) == "_Union(#<Set: {String, Integer, Symbol, Float}>)"
306306+ end
296307end
297308298309test "_Void" do
+16-1
lib/literal/types/union_type.rb
···5566 def initialize(*types)
77 raise Literal::ArgumentError.new("_Union type must have at least one type.") if types.size < 1
88- @types = types.to_set.freeze
88+99+ @types = Set[]
1010+ load_types(types)
1111+ @types.freeze
912 end
10131114 def inspect = "_Union(#{@types.inspect})"
···20232124 def deconstruct
2225 @types.to_a
2626+ end
2727+2828+ protected
2929+3030+ attr_reader :types
3131+3232+ private
3333+3434+ def load_types(types)
3535+ types.each do |type|
3636+ (Literal::Types::UnionType === type) ? load_types(type.types) : @types << type
3737+ end
2338 end
2439end