From 6a54e0c628bf3122a19e9e7c0807adff1876eccb Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 20 Sep 2023 16:23:42 +1200 Subject: [PATCH] Fix invalid call to InexactError in MA.scaling (#3518) --- src/mutable_arithmetics.jl | 4 ++-- test/test_mutable_arithmetics.jl | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mutable_arithmetics.jl b/src/mutable_arithmetics.jl index 35dffe0dcf8..3e18b3eeade 100644 --- a/src/mutable_arithmetics.jl +++ b/src/mutable_arithmetics.jl @@ -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 diff --git a/test/test_mutable_arithmetics.jl b/test/test_mutable_arithmetics.jl index 9e7489fec29..b6fd7375e9a 100644 --- a/test/test_mutable_arithmetics.jl +++ b/test/test_mutable_arithmetics.jl @@ -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