From a9779ff61b260fab559f5af1d0f89a81ffd0cb70 Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Sun, 24 Mar 2024 22:38:12 +0100 Subject: [PATCH] Promote div and / in the same way (#270) --- src/interface.jl | 8 ++++---- test/interface.jl | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index e7c95c5b..74f94903 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -33,16 +33,16 @@ _instantiate(::Type{S}) where {S<:Irrational} = S() _instantiate_zero(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S) _instantiate_oneunit(::Type{S}) where {S<:AbstractIrrational} = _instantiate(S) +# Julia v1.0.x has trouble with inference with the `Vararg` method, see +# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373 function promote_operation_fallback( - ::typeof(/), + op::Union{typeof(/),typeof(div)}, ::Type{S}, ::Type{T}, ) where {S,T} - return typeof(_instantiate_zero(S) / _instantiate_oneunit(T)) + return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T))) end -# Julia v1.0.x has trouble with inference with the `Vararg` method, see -# https://travis-ci.org/jump-dev/JuMP.jl/jobs/617606373 function promote_operation_fallback( op::F, ::Type{S}, diff --git a/test/interface.jl b/test/interface.jl index 489a567d..aed08ecd 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -178,3 +178,12 @@ end @test MA.operate_to!!(T(6), abs, T(7)) == 7 @test MA.operate_to!!(T(6), abs, T(-7)) == 7 end + +@testset "Error-free mutability (issue #240)" begin + for op in (+, -, *, /, div) + for T in + (Float64, BigFloat, Int, BigInt, Rational{Int}, Rational{BigInt}) + @test_nowarn MA.mutability(T, op, T, T) # should run without error + end + end +end