Skip to content

Commit f0046a0

Browse files
authored
Fix promote_typejoin_union with UnionAll (#38428)
The current version returns a type which is narrower than what `typejoin` computes, which can make `broadcast` fail. Return `Any` until we develop code to compute the same result as `typejoin`, as this is only used for inference.
1 parent 382a665 commit f0046a0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

base/broadcast.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ eltypes(t::Tuple) = Tuple{_broadcast_getindex_eltype(t[1]), eltypes(tail(t)).typ
694694
function promote_typejoin_union(::Type{T}) where T
695695
if T === Union{}
696696
return Union{}
697+
elseif T isa UnionAll
698+
return Any # TODO: compute more precise bounds
697699
elseif T isa Union
698700
return promote_typejoin(promote_typejoin_union(T.a), promote_typejoin_union(T.b))
699701
elseif T <: Tuple

test/broadcast.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,4 +987,6 @@ p0 = copy(p)
987987
(1.0, "c") (2, "c") (3, "c")]
988988
@test typeof.([iszero, isdigit]) == [typeof(iszero), typeof(isdigit)]
989989
@test typeof.([iszero, iszero]) == [typeof(iszero), typeof(iszero)]
990+
@test isequal(identity.(Vector{<:Union{Int, Missing}}[[1, 2],[missing, 1]]),
991+
[[1, 2],[missing, 1]])
990992
end

0 commit comments

Comments
 (0)