Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid call to InexactError in MA.scaling #3518

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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