def update_container_elem_type(subst, env, caller_ep, scratch)
case
when @kind == Cell
tyvars = @base_type.klass.type_params.map {|name,| Type::Var.new(name) }
tyvars.each_with_index do |tyvar, idx|
ty = subst[tyvar]
if ty
env, ty = scratch.localize_type(ty, env, caller_ep)
env = scratch.update_container_elem_types(env, caller_ep, @id, @base_type) do |elems|
elems.update(idx, ty)
end
end
end
when @kind == Array
tyvar_elem = Type::Var.new(:Elem)
if subst[tyvar_elem]
ty = subst[tyvar_elem]
env, ty = scratch.localize_type(ty, env, caller_ep)
env = scratch.update_container_elem_types(env, caller_ep, @id, @base_type) do |elems|
elems.update(nil, ty)
end
end
when @kind == Hash
tyvar_k = Type::Var.new(:K)
tyvar_v = Type::Var.new(:V)
if subst[tyvar_k] && subst[tyvar_v]
k_ty = subst[tyvar_k]
v_ty = subst[tyvar_v]
alloc_site = AllocationSite.new(caller_ep)
env, k_ty = scratch.localize_type(k_ty, env, caller_ep, alloc_site.add_id(:k))
env, v_ty = scratch.localize_type(v_ty, env, caller_ep, alloc_site.add_id(:v))
env = scratch.update_container_elem_types(env, caller_ep, @id, @base_type) do |elems|
elems.update(k_ty, v_ty)
end
end
end
env
end