Skip to content

Commit

Permalink
revert promotions of abstract arrays inside other arrays (#47893)
Browse files Browse the repository at this point in the history
(cherry picked from commit 427432e)
  • Loading branch information
KristofferC authored and KristofferC committed Dec 19, 2022
1 parent 8432d4f commit eba98e5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
5 changes: 0 additions & 5 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1277,11 +1277,6 @@ el_same(::Type{T}, a::Type{<:AbstractArray{T,n}}, b::Type{<:AbstractArray{S,n}})
el_same(::Type{T}, a::Type{<:AbstractArray{S,n}}, b::Type{<:AbstractArray{T,n}}) where {T,S,n} = b
el_same(::Type, a, b) = promote_typejoin(a, b)

promote_result(::Type{<:AbstractArray}, ::Type{<:AbstractArray}, ::Type{T}, ::Type{S}) where {T,S} = (@inline; promote_type(T,S))
promote_result(::Type{T}, ::Type{S}, ::Type{Bottom}, ::Type{Bottom}) where {T<:AbstractArray,S<:AbstractArray} = (@inline; promote_typejoin(T,S))
# If no promote_rule is defined, both directions give Bottom. In that case use typejoin on the eltypes instead and give Array as the container.
promote_result(::Type{<:AbstractArray{T,n}}, ::Type{<:AbstractArray{S,n}}, ::Type{Bottom}, ::Type{Bottom}) where {T,S,n} = (@inline; Array{promote_type(T,S),n})

promote_rule(a::Type{UnitRange{T1}}, b::Type{UnitRange{T2}}) where {T1,T2} =
el_same(promote_type(T1, T2), a, b)
UnitRange{T}(r::UnitRange{T}) where {T<:Real} = r
Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ julia> transpose(v) * v # compute the dot product
For a matrix of matrices, the individual blocks are recursively operated on:
```jldoctest
julia> C = reshape(1:4, 2, 2)
2×2 reshape(::UnitRange{Int64}, 2, 2) with eltype Int64:
julia> C = [1 3; 2 4]
2×2 Matrix{Int64}:
1 3
2 4
Expand Down
4 changes: 2 additions & 2 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ end
timesofar("conversions")

@testset "Promotions for size $sz" for (sz, T) in allsizes
@test isequal(promote(falses(sz...), zeros(sz...)),
@test_broken isequal(promote(falses(sz...), zeros(sz...)),
(zeros(sz...), zeros(sz...)))
@test isequal(promote(trues(sz...), ones(sz...)),
@test_broken isequal(promote(trues(sz...), ones(sz...)),
(ones(sz...), ones(sz...)))
ae = falses(1, sz...)
ex = (@test_throws ErrorException promote(ae, ones(sz...))).value
Expand Down
8 changes: 4 additions & 4 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,11 @@ end
@test_throws Base.CanonicalIndexError A[2] .= 0
@test_throws MethodError A[3] .= 0
A = [[1, 2, 3], 4:5]
@test A isa Vector{Vector{Int}}
A[1] .= 0
A[2] .= 0
@test A[1] == [0, 0, 0]
@test A[2] == [0, 0]
@test A[1] isa Vector{Int}
@test A[2] isa UnitRange
@test A[1] == [0,0,0]
@test_throws Base.CanonicalIndexError A[2] .= 0
end

# Issue #22180
Expand Down

0 comments on commit eba98e5

Please sign in to comment.