Skip to content

Commit

Permalink
Fixed a bug in promotion involving ContextUnits where promotion conte…
Browse files Browse the repository at this point in the history
…xt might not be retained.
  • Loading branch information
ajkeller34 committed Apr 5, 2017
1 parent b1b85b5 commit 00fe499
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- v0.2.2
- Fixed a bug in promotion involving `ContextUnits` where the promotion context might
not be properly retained.
- v0.2.1
- Fixed `isapprox` bug [#74](https://github.com/ajkeller34/Unitful.jl/pull/74).
- Added `DimensionlessQuantity` methods for `exp`, `exp10`, `exp2`, `expm1`, `log1p`,
Expand Down
5 changes: 3 additions & 2 deletions src/Promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ function Base.promote_rule{S1,S2,D,U1,U2}(::Type{Quantity{S1,D,U1}},
typeof(convfact(p,U1())), typeof(convfact(p,U2())))
if !isunitless(p)
if U1 <: ContextUnits && U2 <: ContextUnits
if upreferred(U1()) === upreferred(U2())
return Quantity{numtype,D,typeof(ContextUnits(p,p))}
up1 = upreferred(U1())
if up1 === upreferred(U2())
return Quantity{numtype,D,typeof(ContextUnits(p,up1))}
else
return Quantity{numtype,D,typeof(p)}
end
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ end
μm2mm = ContextUnits(μm,mm)
@test @inferred(promote(1.0nm2μm, 1.0m)) === (0.001μm2μm, 1e6μm2μm)
@test @inferred(promote(1.0m, 1.0μm2μm)) === (1e6μm2μm, 1.0μm2μm)
@test ===(upreferred.(unit.(promote(1.0nm2μm, 2nm2μm)))[1], ContextUnits(μm,μm))
@test ===(upreferred.(unit.(promote(1.0nm2μm, 2nm2μm)))[2], ContextUnits(μm,μm))

# Context agreement
@test @inferred(promote(1.0nm2μm, 1.0μm2μm)) ===
Expand Down

0 comments on commit 00fe499

Please sign in to comment.