This is fixed in the upcoming 1.9.1 release already:
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.9.0 (2023-05-28)
_/ |\__'_|_|_|\__'_| | release-1.9/a7348b7aa9d (fork: 342 commits, 199 days)
|__/ |
julia> types = [:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15];
julia> typesunion = Union{[Val{x} for x in types]...};
julia> struct obj{T<:typesunion}
a::Int64
end
julia> objtypesunion = Union{[obj{Val{x}} for x in types]...};
julia> @time objvec = objtypesunion[]
0.017479 seconds (5.71 k allocations: 381.589 KiB, 96.79% compilation time)
Union{obj{Val{1}}, obj{Val{2}}, obj{Val{3}}, obj{Val{4}}, obj{Val{5}}, obj{Val{6}}, obj{Val{7}}, obj{Val{8}}, obj{Val{9}}, obj{Val{10}}, obj{Val{11}}, obj{Val{12}}, obj{Val{13}}, obj{Val{14}}, obj{Val{15}}}[]