Skip to content

Commit

Permalink
promotion: symmetrize promotion rules recursively with promote_type.
Browse files Browse the repository at this point in the history
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
StefanKarpinski committed Jan 21, 2014
1 parent 6bae16d commit c5591e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/promotion.jl
Expand Up @@ -112,7 +112,7 @@ promote_type{T,S}(::Type{T}, ::Type{S}) =


promote_rule(T, S) = None 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 # If no promote_rule is defined, both directions give None. In that
# case use typejoin on the original types instead. # case use typejoin on the original types instead.
promote_result{T,S}(::Type{T},::Type{S},::Type{None},::Type{None}) = typejoin(T, S) promote_result{T,S}(::Type{T},::Type{S},::Type{None},::Type{None}) = typejoin(T, S)
Expand Down
5 changes: 5 additions & 0 deletions test/numbers.jl
Expand Up @@ -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) @test convert(T,n*(n^typemax(T))) == one(T)
end end
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.