Skip to content

Commit 58e6bf3

Browse files
committed
Fix complex ambiguity
1 parent 50e3f2d commit 58e6bf3

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/disambiguities.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ for type in (:(Complex), :(Complex{Bool}))
6060
function Base.:*(l::AbstractRealQuantity, r::$type)
6161
new_quantity(typeof(l), ustrip(l) * r, dimension(l))
6262
end
63-
function $type(q::AbstractRealQuantity)
64-
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
65-
return $type(ustrip(q))
66-
end
6763
end
6864
end
69-
function Bool(q::AbstractRealQuantity)
65+
function Complex{T}(q::AbstractRealQuantity) where {T<:Real}
7066
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
71-
return Bool(ustrip(q))
67+
return Complex{T}(ustrip(q))
68+
end
69+
for type in (:Bool, :Complex)
70+
@eval function $type(q::AbstractRealQuantity)
71+
@assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead."
72+
return $type(ustrip(q))
73+
end
7274
end
7375
function Base.:/(l::Complex, r::AbstractRealQuantity)
7476
new_quantity(typeof(r), l / ustrip(r), inv(dimension(r)))

test/unittests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ end
848848
@test typeof(out) == with_type_parameters(promote_quantity_on_value(Q, ComplexF64), Complex{Float64}, DEFAULT_DIM_TYPE)
849849
@test ustrip(out) 0.5 ^ (1 + 2im)
850850

851-
for CT in (Complex, Complex{Float32})
851+
for CT in (Complex, Complex{Bool})
852852
x = Q(1.0)
853853
@test CT(x) == CT(1.0)
854854
@test typeof(CT(x)) <: CT

0 commit comments

Comments
 (0)