Here's my best attempt at reproduction (the actual case is https://github.com/JuliaMolSim/DFTK.jl/blob/master/src/fft.jl#L47)
function f(x; isreal=true)
y = similar(x)
y .= x
isreal ? real(y) : y
end
@code_warntype f(randn(ComplexF64, 1))
gives a ::Union{Vector{ComplexF64}, Vector{Float64}}. This is on 1.7 and on master. Removing the y .= x or moving isreal to a Val both fix the issue. y[:] = x[:] also has the inference failure.