diff --git a/src/attributes.jl b/src/attributes.jl index 2d2f1c19ed..f7904c6fef 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -396,6 +396,9 @@ end # get(::ModelLike, ::AbstractVariableAttribute, ::Vector{VariableIndex}) # would not allow us to define get(::SomeModel, ::AnyAttribute, ::Vector). function get(model::ModelLike, attr::AnyAttribute, idxs::Vector) + if isempty(idxs) + return Vector{attribute_value_type(attr)}() + end return get.(model, attr, idxs) end diff --git a/test/attributes.jl b/test/attributes.jl index 929ad53a88..8fd5d8641c 100644 --- a/test/attributes.jl +++ b/test/attributes.jl @@ -316,6 +316,23 @@ function test_attributes_AutomaticDifferentiationBackend() return end +function test_empty_vector_attribute() + model = MOI.Utilities.Model{Float64}() + x = MOI.get(model, MOI.ListOfVariableIndices()) + @test typeof(x) == Vector{MOI.VariableIndex} + ret = MOI.get(model, MOI.VariablePrimalStart(), x) + @test typeof(ret) == Vector{Any} + ret = MOI.get(model, MOI.VariableName(), x) + @test typeof(ret) == Vector{String} + F, S = MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64} + c = MOI.get(model, MOI.ListOfConstraintIndices{F,S}()) + ret = MOI.get(model, MOI.ConstraintPrimalStart(), c) + @test typeof(ret) == Vector{Any} + ret = MOI.get(model, MOI.ConstraintName(), c) + @test typeof(ret) == Vector{String} + return +end + function runtests() for name in names(@__MODULE__; all = true) if startswith("$name", "test_")