diff --git a/src/variables.jl b/src/variables.jl index 8f37480f3e3..203722e9e00 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -1750,7 +1750,9 @@ function _moi_add_variable( return var_ref end -function _to_value(::Type{T}, value, msg) where {T} +_to_value(::Type{T}, value::T, ::String) where {T} = value + +function _to_value(::Type{T}, value, msg::String) where {T} try return convert(T, value) catch @@ -1761,9 +1763,7 @@ function _to_value(::Type{T}, value, msg) where {T} end end -_to_value(::Type{T}, value::T, ::String) where {T} = value - -function _to_value(::Type{T}, value::AbstractJuMPScalar, msg) where {T} +function _to_value(::Type{T}, value::AbstractJuMPScalar, msg::String) where {T} return error( "Unable to use `$value::$(typeof(value))` as the $msg of a variable. " * "The $msg must be a constant value of type `::$T`. You cannot use " * @@ -1771,7 +1771,6 @@ function _to_value(::Type{T}, value::AbstractJuMPScalar, msg) where {T} ) end - function _moi_constrain_variable( moi_backend::MOI.ModelLike, index, diff --git a/test/test_variable.jl b/test/test_variable.jl index 082a40be935..6f3f50205ae 100644 --- a/test/test_variable.jl +++ b/test/test_variable.jl @@ -1587,7 +1587,7 @@ function test_bad_bound_types() function err2(value, msg, T) return ErrorException( "Unable to use `$value::$(typeof(value))` as the $msg of a variable. " * - "The $msg must be a constant value of type `::$T`. You cannot use " * + "The $msg must be a constant value of type `::$T`. You cannot use " * "JuMP variables or expressions.", ) end