Skip to content

Commit

Permalink
Fix invalid call to InexactError in MA.scaling (#3518)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 20, 2023
1 parent 1ee5fae commit 6a54e0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mutable_arithmetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ end
# `scaling` to convert them back to numbers.
function _MA.scaling(aff::GenericAffExpr{C}) where {C}
if !isempty(aff.terms)
throw(InexactError("Cannot convert `$aff` to `$C`."))
throw(InexactError(Symbol("MutableArithmetics.scaling"), C, aff))
end
return _MA.scaling(aff.constant)
end

function _MA.scaling(quad::GenericQuadExpr{C}) where {C}
if !isempty(quad.terms)
throw(InexactError("Cannot convert `$quad` to `$C`."))
throw(InexactError(Symbol("MutableArithmetics.scaling"), C, quad))
end
return _MA.scaling(quad.aff)
end
Expand Down
8 changes: 8 additions & 0 deletions test/test_mutable_arithmetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,12 @@ function test_extension_different_variables(
return
end

function test_scaling_errors()
model = Model()
@variable(model, x)
@test_throws InexactError JuMP._MA.scaling(x + 1.0)
@test_throws InexactError JuMP._MA.scaling(x^2 + 1.0)
return
end

end

0 comments on commit 6a54e0c

Please sign in to comment.