diff --git a/src/JuMP.jl b/src/JuMP.jl index 9bc01c96cad..659709c6b41 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -1049,6 +1049,9 @@ function owner_model end Base.ndims(::Type{<:AbstractJuMPScalar}) = 0 Base.ndims(::AbstractJuMPScalar) = 0 +Base.IteratorEltype(::Type{<:AbstractJuMPScalar}) = Base.HasEltype() +Base.eltype(::Type{T}) where {T<:AbstractJuMPScalar} = T + # These are required to create symmetric containers of AbstractJuMPScalars. LinearAlgebra.symmetric_type(::Type{T}) where {T<:AbstractJuMPScalar} = T LinearAlgebra.hermitian_type(::Type{T}) where {T<:AbstractJuMPScalar} = T diff --git a/test/test_variable.jl b/test/test_variable.jl index cfa83ec768e..773c2527a2d 100644 --- a/test/test_variable.jl +++ b/test/test_variable.jl @@ -1608,4 +1608,12 @@ function test_variable_length() return end +function test_variable_eltype() + model = Model() + @variable(model, x) + @test Base.IteratorEltype(x) == Base.HasEltype() + @test Base.eltype(typeof(x)) == typeof(x) + return +end + end # module TestVariable