Permalink
Browse files

promotion: symmetrize promotion rules recursively with promote_type.

If promote_rule(T,S) and promote_rule(S,T) disagree, call promote_type
again on the results to get a single common answer. This can resolve
cases where there is a conflict between two such rules, making the
promotion system a bit more robust.
  • Loading branch information...
1 parent 6bae16d commit c5591e7d76515cbc5bff8ccc1fe5efbf1642a533 @StefanKarpinski StefanKarpinski committed Jan 21, 2014
Showing with 6 additions and 1 deletion.
  1. +1 −1 base/promotion.jl
  2. +5 −0 test/numbers.jl
View
2 base/promotion.jl
@@ -112,7 +112,7 @@ promote_type{T,S}(::Type{T}, ::Type{S}) =
promote_rule(T, S) = None
-promote_result(t,s,T,S) = typejoin(T,S)
+promote_result(t,s,T,S) = promote_type(T,S)
# If no promote_rule is defined, both directions give None. In that
# case use typejoin on the original types instead.
promote_result{T,S}(::Type{T},::Type{S},::Type{None},::Type{None}) = typejoin(T, S)
View
5 test/numbers.jl
@@ -1742,3 +1742,8 @@ for T = (Uint8,Int8,Uint16,Int16,Uint32,Int32,Uint64,Int64,Uint128,Int128)
@test convert(T,n*(n^typemax(T))) == one(T)
end
end
+
+@test is(false*pi, 0.0)
+@test is(true*pi, float64(pi))
+@test is(pi*false, 0.0)
+@test is(pi*true, float64(pi))

0 comments on commit c5591e7

Please sign in to comment.