Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ promote_unit(x::Units, y::Units, z::Units, t::Units...) =
@inline _promote_unit(x::ContextUnits{N,D,P,A}, y::ContextUnits{N,D,P,A}) where {N,D,P,A} = x #ambiguity reasons
# same units, but promotion context disagrees
@inline _promote_unit(x::ContextUnits{N,D,P1,A}, y::ContextUnits{N,D,P2,A}) where {N,D,P1,P2,A} =
ContextUnits{N,D,promote_unit(P1(), P2()),A}()
ContextUnits{N,D,typeof(promote_unit(P1(), P2())),A}()
# different units, but promotion context agrees
@inline _promote_unit(x::ContextUnits{N1,D,P}, y::ContextUnits{N2,D,P}) where {N1,N2,D,P} =
ContextUnits(P(), P())
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ Unitful.uconvert(U::Unitful.Units, q::QQQ) = uconvert(U, Quantity(q.val, cm))
(1.0μm2μm, 1.0nm2μm, 1.0s)
# Context disagreement: fall back to free units
@test @inferred(promote(1.0nm2μm, 1.0μm2mm)) === (1e-9m, 1e-6m)
# Same units, context disagreement
μm2m = ContextUnits(μm, m)
@test @inferred(promote(1.0μm2μm, 1.0μm2mm)) === (1.0μm2m, 1.0μm2m)
end
@testset "> Promotion during array creation" begin
@test typeof([1.0m,1.0m]) == Array{typeof(1.0m),1}
Expand Down
Loading