diff --git a/src/Test/UnitTests/attributes.jl b/src/Test/UnitTests/attributes.jl index 9c99698018..d6532cb407 100644 --- a/src/Test/UnitTests/attributes.jl +++ b/src/Test/UnitTests/attributes.jl @@ -157,17 +157,18 @@ for attr in ( MOI.optimize!(model) attribute = MOI.$(attr)() T = MOI.attribute_value_type(attribute) - # Use this syntax if T is a small union like Union{Nothing,Int}. - @test @inferred(T, MOI.get(model, attribute)) isa T + if VERSION < 1.5 + @test MOI.get(model, attribute) isa T + else + @test @inferred(T, MOI.get(model, attribute)) isa T + end end # unittests["test_attribute_$(attr)"] end end # Variable attributes. -for attr in ( - :VariableName, -) +for attr in (:VariableName,) f = Symbol("test_attribute_$(attr)") @eval begin function $(f)(model::MOI.ModelLike, config::TestConfig) @@ -177,7 +178,11 @@ for attr in ( MOI.optimize!(model) attribute = MOI.$(attr)() T = MOI.attribute_value_type(attribute) - @test @inferred(T, MOI.get(model, attribute, x)) isa T + if VERSION < 1.5 + @test MOI.get(model, attribute, x) isa T + else + @test @inferred(T, MOI.get(model, attribute, x)) isa T + end end # unittests["test_attribute_$(attr)"] end @@ -204,7 +209,11 @@ for attr in ( MOI.set(model, MOI.ConstraintName(), ci, "ci") attribute = MOI.$(attr)() T = MOI.attribute_value_type(attribute) - @test @inferred(T, MOI.get(model, attribute, ci)) isa T + if VERSION < 1.5 + @test MOI.get(model, attribute, ci) isa T + else + @test @inferred(T, MOI.get(model, attribute, ci)) isa T + end end # unittests["test_attribute_$(attr)"] end diff --git a/src/Utilities/cachingoptimizer.jl b/src/Utilities/cachingoptimizer.jl index e5dfd41fd5..45a0e0b51f 100644 --- a/src/Utilities/cachingoptimizer.jl +++ b/src/Utilities/cachingoptimizer.jl @@ -688,10 +688,7 @@ function MOI.supports( (m.state == NO_OPTIMIZER || MOI.supports(m.optimizer, attr)) end -function MOI.get( - model::CachingOptimizer, - attr::MOI.AbstractModelAttribute, -) +function MOI.get(model::CachingOptimizer, attr::MOI.AbstractModelAttribute) if MOI.is_set_by_optimize(attr) if state(model) == NO_OPTIMIZER if attr == MOI.TerminationStatus() @@ -883,7 +880,7 @@ function MOI.get( MOI.get( m.optimizer, attr.attr, - m.model_to_optimizer_map[idx] + m.model_to_optimizer_map[idx], )::MOI.attribute_value_type(attr.attr), ) end diff --git a/src/attributes.jl b/src/attributes.jl index c3438b674f..10c94a3216 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -1376,7 +1376,9 @@ A constraint attribute indicating whether the constraint participates in the conflict. Its type is [`ConflictParticipationStatusCode`](@ref). """ struct ConstraintConflictStatus <: AbstractConstraintAttribute end -attribute_value_type(::ConstraintConflictStatus) = ConflictParticipationStatusCode +function attribute_value_type(::ConstraintConflictStatus) + return ConflictParticipationStatusCode +end ## Termination status @@ -1606,8 +1608,7 @@ end # Cost of bridging F-in-S constraints struct ConstraintBridgingCost{F<:AbstractFunction,S<:AbstractSet} <: - AbstractModelAttribute -end + AbstractModelAttribute end attribute_value_type(::ConstraintBridgingCost) = Float64 diff --git a/test/Utilities/mockoptimizer.jl b/test/Utilities/mockoptimizer.jl index a0b36d9f3e..d7e0994d67 100644 --- a/test/Utilities/mockoptimizer.jl +++ b/test/Utilities/mockoptimizer.jl @@ -234,7 +234,7 @@ end @testset "test_model_optimizer_attributes" begin model = MOI.Utilities.MockOptimizer( - MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), ) config = MOI.Test.TestConfig() MOI.set(model, MOI.NumberOfThreads(), 4) @@ -282,7 +282,7 @@ end @testset "test_variable_attributes" begin model = MOI.Utilities.MockOptimizer( - MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), ) config = MOI.Test.TestConfig() MOI.Test.test_attribute_VariableName(model, config) @@ -290,7 +290,7 @@ end @testset "test_constraint_attributes" begin model = MOI.Utilities.MockOptimizer( - MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), ) config = MOI.Test.TestConfig() MOI.Test.test_attribute_ConstraintFunction(model, config)