Skip to content

Commit

Permalink
Fix ambiguity error in ^ on recent 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Feb 17, 2017
1 parent 96bad5d commit b6fdfaf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,13 @@ end

# Both methods needed for ambiguity resolution
^{T}(x::Dimension{T}, y::Integer) = Dimension{T}(power(x)*y)
^{T,y}(x::Dimension{T}, ::Type{Val{y}}) = Dimension{T}(power(x)*y)
^{T}(x::Dimension{T}, y) = Dimension{T}(power(x)*y)

# A word of caution:
# Exponentiation is not type-stable for `Dimensions` objects.
^{T}(x::Dimensions{T}, y::Integer) = *(Dimensions{map(a->a^y, T)}())
^{T,y}(x::Dimensions{T}, ::Type{Val{y}}) = *(Dimensions{map(a->a^y, T)}())
^{T}(x::Dimensions{T}, y) = *(Dimensions{map(a->a^y, T)}())

@inline dimension{U,D}(u::Unit{U,D}) = D()^u.power
Expand Down Expand Up @@ -1011,12 +1013,14 @@ end

# Both methods needed for ambiguity resolution
^{U,D}(x::Unit{U,D}, y::Integer) = Unit{U,D}(tens(x), power(x)*y)
^{U,D,y}(x::Unit{U,D}, ::Type{Val{y}}) = Unit{U,D}(tens(x), power(x)*y)
^{U,D}(x::Unit{U,D}, y) = Unit{U,D}(tens(x), power(x)*y)

# A word of caution:
# Exponentiation is not type-stable for `Units` objects.
# Dimensions get reconstructed anyway so we pass () for the D type parameter...
^{U,D}(x::Units{U,D}, y::Integer) = *(Units{map(a->a^y, U), ()}())
^{U,D,y}(x::Units{U,D}, ::Type{Val{y}}) = *(Units{map(a->a^y, U), ()}())
^{U,D}(x::Units{U,D}, y) = *(Units{map(a->a^y, U), ()}())

# All of these are needed for ambiguity resolution
Expand Down

0 comments on commit b6fdfaf

Please sign in to comment.