Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for ambiguities? #439

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion src/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ promote_unit(x::Units, y::Units, z::Units, t::Units...) =
@inline _promote_unit(x::FreeUnits{N1,D}, y::FreeUnits{N2,D}) where {N1,N2,D} =
upreferred(dimension(x))

@inline _promote_unit(x::T, y::T) where {T <: ContextUnits} = T() #ambiguity reasons
@inline _promote_unit(x::ContextUnits{N,D,P,A}, y::ContextUnits{N,D,P,A}) where {N,D,P,A} =
ContextUnits{N,D,P,A}() # 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}()
Expand Down
1 change: 1 addition & 0 deletions src/quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ for (_x,_y) in [(:fma, :_fma), (:muladd, :_muladd)]
# Catch some signatures pre-promotion
@eval @inline ($_x)(x::Number, y::AbstractQuantity, z::AbstractQuantity) = ($_y)(x,y,z)
@eval @inline ($_x)(x::AbstractQuantity, y::Number, z::AbstractQuantity) = ($_y)(x,y,z)
@eval @inline ($_x)(x::AbstractQuantity, y::AbstractQuantity, z::AbstractQuantity) = ($_y)(x,y,z)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this method means that the one below it can be deleted (it’s the same but with unused type parameters).


# Post-promotion
@eval @inline ($_x)(x::AbstractQuantity{A}, y::AbstractQuantity{B}, z::AbstractQuantity{C}) where {
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ using Dates:

const colon = Base.:(:)

@testset "Ambiguities" begin
ambig = sort(detect_ambiguities(Unitful), by = a -> [string(a[1].name), string(a[2].module)])
if length(ambig) > 0
println(stdout, "detect_ambiguities(Unitful) found $(length(ambig)) issues:")
for i in 1:length(ambig)
println(stdout, "[",i, "]:")
println(stdout, " ", ambig[i][1])
println(stdout, " ", ambig[i][2])
end
println(stdout)
end
@test length(ambig) <= 27
unbound = detect_unbound_args(Unitful)
@test length(unbound) <= 1
end

@testset "Construction" begin
@test isa(NoUnits, FreeUnits)
@test typeof(𝐋) === Unitful.Dimensions{(Unitful.Dimension{:Length}(1),)}
Expand Down