Skip to content

Commit

Permalink
Flatten recursive union
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Dec 20, 2023
1 parent 5a44fc6 commit c0cdc8e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/typeprof/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,19 @@ def initialize

def []=(k_ty, v_ty)
k_ty.each_child_global do |k_ty|
# This is a temporal hack to mitigate type explosion
k_ty = Type.any if k_ty.is_a?(Type::Array)
k_ty = Type.any if k_ty.is_a?(Type::Hash)

if @map_tys[k_ty]
@map_tys[k_ty] = @map_tys[k_ty].union(v_ty)
if k_ty.is_a?(Type::Union)
# Flatten recursive union
self[k_ty] = v_ty
else
@map_tys[k_ty] = v_ty
# This is a temporal hack to mitigate type explosion
k_ty = Type.any if k_ty.is_a?(Type::Array)
k_ty = Type.any if k_ty.is_a?(Type::Hash)

if @map_tys[k_ty]
@map_tys[k_ty] = @map_tys[k_ty].union(v_ty)
else
@map_tys[k_ty] = v_ty
end
end
end
end
Expand Down

0 comments on commit c0cdc8e

Please sign in to comment.