diff --git a/src/Utilities/cachingoptimizer.jl b/src/Utilities/cachingoptimizer.jl index 2542ac1da1..2826f56413 100644 --- a/src/Utilities/cachingoptimizer.jl +++ b/src/Utilities/cachingoptimizer.jl @@ -901,6 +901,7 @@ function MOI.get( "optimizer is attached.", ) end + MOI.check_result_index_bounds(model, attr) try return MOI.get( model.optimizer, @@ -923,6 +924,7 @@ function MOI.get( "optimizer is attached.", ) end + MOI.check_result_index_bounds(model, attr) try return MOI.get( model.optimizer, diff --git a/test/Utilities/cachingoptimizer.jl b/test/Utilities/cachingoptimizer.jl index 08fb022f64..44211802d2 100644 --- a/test/Utilities/cachingoptimizer.jl +++ b/test/Utilities/cachingoptimizer.jl @@ -814,6 +814,8 @@ MOI.get(::_ConstraintPrimal1310, ::MOI.ListOfModelAttributesSet) = [] MOI.get(::_ConstraintPrimal1310, ::MOI.PrimalStatus) = MOI.FEASIBLE_POINT +MOI.get(::_ConstraintPrimal1310, ::MOI.ResultCount) = 1 + function MOI.optimize!(::_ConstraintPrimal1310, model::MOI.ModelLike) index_map = MOI.IndexMap() for x in MOI.get(model, MOI.ListOfVariableIndices()) @@ -845,6 +847,14 @@ function test_ConstraintPrimal_fallback() MOI.optimize!(model) @test MOI.get(model, MOI.ConstraintPrimal(), c) == 1.2 @test MOI.get(model, MOI.ConstraintPrimal(), [c]) == [1.2] + @test_throws( + MOI.ResultIndexBoundsError(MOI.ConstraintPrimal(2), 1), + MOI.get(model, MOI.ConstraintPrimal(2), c), + ) + @test_throws( + MOI.ResultIndexBoundsError(MOI.ConstraintPrimal(2), 1), + MOI.get(model, MOI.ConstraintPrimal(2), [c]), + ) return end