Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ const NonleafHandlingStyles = Union{DefaultArrayStyle,ArrayConflict}
# Now handle the remaining values
# The typeassert gives inference a helping hand on the element type and dimensionality
# (work-around for #28382)
ElType′ = ElType <: Type ? Type : ElType
ElType′ = ElType === Union{} ? Any : ElType <: Type ? Type : ElType
RT = dest isa AbstractArray ? AbstractArray{<:ElType′, ndims(dest)} : Any
return copyto_nonleaf!(dest, bc′, iter, state, 1)::RT
end
Expand Down
15 changes: 15 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,18 @@ p0 = copy(p)
@test isequal(identity.(Vector{<:Union{Int, Missing}}[[1, 2],[missing, 1]]),
[[1, 2],[missing, 1]])
end

@testset "Issue #28382: eltype inconsistent with getindex" begin
struct Cyclotomic <: Number
end

Base.getindex(x::Cyclotomic, i::Integer) = i

Base.length(x::Cyclotomic) = 1
Base.eltype(::Type{<:Cyclotomic}) = Tuple{Int,Int}

Base.:*(c::T, x::Cyclotomic) where {T<:Real} = [1, 2]
Base.:*(x::Cyclotomic, c::T) where {T<:Real} = [1, 2]

@test Cyclotomic() .* [2, 3] == [[1, 2], [1, 2]]
end