From 087e4b04c3ee4cb970bd2da8169be72fbb073d81 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Thu, 29 Dec 2016 14:29:52 -0500 Subject: [PATCH] Integer /: restrict fallback to same-type case (fix #19714) The principle here is that if there's an implementation of a promoted operator for some type and promotions for that type, unless other methods are defined, the operation should always be "funnelled" through the core operator definition for that type. The method for `/(::Integer, ::Integer)` violated that principle since it would take precedence in mixed-integer-type division cases even in the presence of a same-type method definition for a custom integer type and the appropriate promotion rules. --- base/int.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/int.jl b/base/int.jl index 3ee0b62e4b59f..727d3333ab5b8 100644 --- a/base/int.jl +++ b/base/int.jl @@ -32,8 +32,9 @@ typealias BitUnsigned64T Union{Type{UInt8},Type{UInt16},Type{UInt32},Type{UInt64 +{T<:BitInteger}(x::T, y::T) = box(T, add_int(unbox(T,x),unbox(T,y))) *{T<:BitInteger}(x::T, y::T) = box(T, mul_int(unbox(T,x),unbox(T,y))) -/(x::Integer, y::Integer) = float(x)/float(y) inv(x::Integer) = float(one(x))/float(x) +/{T<:Integer}(x::T, y::T) = float(x)/float(y) +/(x::BitInteger, y::BitInteger) = float(x)/float(y) """ isodd(x::Integer) -> Bool