Skip to content
Merged
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
5 changes: 3 additions & 2 deletions Compiler/src/typeutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ function _switchtupleunion(𝕃::AbstractLattice, t::Vector{Any}, i::Int, tunion
_switchtupleunion(𝕃, t, i - 1, tunion, origt)
end
t[i] = origti
elseif has_extended_unionsplit(𝕃) && !isa(ti, Const) && !isvarargtype(ti) && isa(widenconst(ti), Union)
for ty in uniontypes(ti)
elseif (has_extended_unionsplit(𝕃) && !isa(ti, Const) && !isvarargtype(ti) &&
(wty = widenconst(ti); isa(wty, Union)))
for ty in uniontypes(wty)
t[i] = ty
_switchtupleunion(𝕃, t, i - 1, tunion, origt)
end
Expand Down
9 changes: 9 additions & 0 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,15 @@ end == Integer
Val(isdefined(xxx.value, :x))
end == Val{true}

# Test union splitting for MustAlias
struct GetSomethingA; x::Union{Nothing,Int}; end
struct GetSomethingB; x::Int; end
getsomethingx(a::GetSomethingA) = something(a.x, 0)
getsomethingx(b::GetSomethingB) = b.x
@test Base.infer_return_type((Union{GetSomethingA,GetSomethingB},); interp=MustAliasInterpreter()) do x
getsomethingx(x)
end == Int

@testset "issue #56913: `BoundsError` in type inference" begin
R = UnitRange{Int}
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, Vararg{R}})
Expand Down