Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/typeprof/core/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scenario/array/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ def check

## assert
class Object
def check: -> (Array[Integer] | [])
def check: -> (Array[:foo] | Array[Integer])
end
Loading