Skip to content

Commit

Permalink
Promote div and / in the same way (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
hersle authored Mar 24, 2024
1 parent 5e901e1 commit a9779ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
9 changes: 9 additions & 0 deletions test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a9779ff

Please sign in to comment.