diff --git a/lib/typeprof/core/type.rb b/lib/typeprof/core/type.rb index 512fe38e0..b901f3307 100644 --- a/lib/typeprof/core/type.rb +++ b/lib/typeprof/core/type.rb @@ -160,10 +160,18 @@ def base_type(genv) end def show - if @elems + if @elems && !extended? "[#{ @elems.map {|e| Type.strip_parens(e.show) }.join(", ") }]" else - "#{ @base_type.mod.show_cpath }[#{ Type.strip_parens(@unified_elem.show) }]" + @base_type.show + end + end + + # Whether the unified element has a type that comes from none of the + # tuple elements, e.g., `ary = []; ary << 1` + def extended? + @base_type.args.first.types.each_key.any? do |ty| + @elems.none? {|elem| elem.types.include?(ty) } end end end diff --git a/scenario/known-issues/accumulator-in-block.rb b/scenario/array/accumulator-in-block.rb similarity index 76% rename from scenario/known-issues/accumulator-in-block.rb rename to scenario/array/accumulator-in-block.rb index 4ff981285..501b54d90 100644 --- a/scenario/known-issues/accumulator-in-block.rb +++ b/scenario/array/accumulator-in-block.rb @@ -27,3 +27,15 @@ def collect(arr) class Object def collect: ([String, String]) -> Array[[Integer, String]] end + +## update +def foo + ary = [1] + ary << "str" + ary +end + +## assert +class Object + def foo: -> Array[Integer | String] +end diff --git a/scenario/array/push.rb b/scenario/array/push.rb index 5609db3de..ce2b978eb 100644 --- a/scenario/array/push.rb +++ b/scenario/array/push.rb @@ -10,5 +10,5 @@ def check ## assert class Object - def check: -> (Array[Integer] | []) + def check: -> (Array[:foo] | Array[Integer]) end