From 0fe9cfcddaca5d093f46302db770cac4d960437f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 19 Sep 2026 11:18:48 +0200 Subject: [PATCH 1/2] Fix head_to_set for custom sets --- src/FileFormats/MOF/read.jl | 2 +- test/FileFormats/MOF/test_MOF.jl | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/FileFormats/MOF/read.jl b/src/FileFormats/MOF/read.jl index 963fc90215..a3ca5e7e27 100644 --- a/src/FileFormats/MOF/read.jl +++ b/src/FileFormats/MOF/read.jl @@ -189,7 +189,7 @@ macro head_to_val(f, arg1, args...) push!(leaf.args, new_expr) leaf = new_expr end - push!(leaf.args, Expr(:return, Val(head))) + push!(leaf.args, :(return Val(Symbol($head)))) quote function $(esc(f))($head::String) return $body diff --git a/test/FileFormats/MOF/test_MOF.jl b/test/FileFormats/MOF/test_MOF.jl index e274faabcc..c05d9d35a5 100644 --- a/test/FileFormats/MOF/test_MOF.jl +++ b/test/FileFormats/MOF/test_MOF.jl @@ -1681,6 +1681,14 @@ function test_unsupported_objectives() return end +function test_head_to_val() + @test MOF.head_to_set("Nonnegatives") === Val(:Nonnegatives) + @test MOF.head_to_set("CustomSet") === Val(:CustomSet) + @test MOF.head_to_function("VectorOfVariables") === Val(:VectorOfVariables) + @test MOF.head_to_function("CustomFunction") === Val(:CustomFunction) + return +end + function test_unsupported_kwarg() @test_throws( ErrorException( From 5d7468552fe39b1fcc3d215adeeae6cadceff380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 19 Sep 2026 11:31:38 +0200 Subject: [PATCH 2/2] Add test --- test/FileFormats/MOF/test_MOF.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/FileFormats/MOF/test_MOF.jl b/test/FileFormats/MOF/test_MOF.jl index c05d9d35a5..3f6414995f 100644 --- a/test/FileFormats/MOF/test_MOF.jl +++ b/test/FileFormats/MOF/test_MOF.jl @@ -1681,6 +1681,21 @@ function test_unsupported_objectives() return end +struct CustomSet <: MOI.AbstractVectorSet + dimension::Int +end + +function MOF.set_to_moi(::Val{:CustomSet}, object::Dict) + return CustomSet(object["dimension"]) +end + +function test_custom_set_to_moi() + object = Dict{String,Any}("type" => "CustomSet", "dimension" => 3) + @test MOF.set_to_moi(Val(:CustomSet), Float64, object) == CustomSet(3) + @test MOF.set_to_moi(Float64, object) == CustomSet(3) + return +end + function test_head_to_val() @test MOF.head_to_set("Nonnegatives") === Val(:Nonnegatives) @test MOF.head_to_set("CustomSet") === Val(:CustomSet)