From 4c407e92d554c359b79e9ef32dba0e1f19285ed3 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 22 Sep 2023 11:23:18 +1200 Subject: [PATCH] Fix various JET errors --- src/Bridges/Constraint/bridges/set_dot_scaling.jl | 4 ++-- src/Utilities/matrix_of_constraints.jl | 9 +++++++-- src/Utilities/struct_of_constraints.jl | 3 ++- src/sets.jl | 3 ++- test/Utilities/matrix_of_constraints.jl | 5 +++++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Bridges/Constraint/bridges/set_dot_scaling.jl b/src/Bridges/Constraint/bridges/set_dot_scaling.jl index 0eef72de82..36cee0f65f 100644 --- a/src/Bridges/Constraint/bridges/set_dot_scaling.jl +++ b/src/Bridges/Constraint/bridges/set_dot_scaling.jl @@ -47,7 +47,7 @@ end function MOI.Bridges.map_set( ::Type{<:SetDotScalingBridge{T,S}}, set::S, -) where {T,S} +) where {T,S<:MOI.AbstractVectorSet} return MOI.Scaled(set) end @@ -158,7 +158,7 @@ end function MOI.Bridges.inverse_map_set( ::Type{<:SetDotInverseScalingBridge{T,S}}, set::S, -) where {T,S} +) where {T,S<:MOI.AbstractVectorSet} return MOI.Scaled(set) end diff --git a/src/Utilities/matrix_of_constraints.jl b/src/Utilities/matrix_of_constraints.jl index 843f2262cc..9527a0c48c 100644 --- a/src/Utilities/matrix_of_constraints.jl +++ b/src/Utilities/matrix_of_constraints.jl @@ -228,7 +228,12 @@ function set_from_constants end Return the list of the types of the sets allowed in `sets`. """ -function set_types end +function set_types(f::Any) + # Because these methods get defined in rather obtuse macros, it helps JET to + # have a default fallback implementation, even if it's identical to what + # would happen regardless. + return throw(MethodError(set_types, (typeof(f),))) +end """ set_index(sets, ::Type{S})::Union{Int,Nothing} where {S<:MOI.AbstractSet} @@ -271,7 +276,7 @@ function rows end MOI.is_empty(v::MatrixOfConstraints) = MOI.is_empty(v.sets) -function MOI.empty!(v::MatrixOfConstraints{T,AT,BT,ST}) where {T,AT,BT,ST} +function MOI.empty!(v::MatrixOfConstraints{T}) where {T} MOI.empty!(v.coefficients) empty!(v.constants) MOI.empty!(v.sets) diff --git a/src/Utilities/struct_of_constraints.jl b/src/Utilities/struct_of_constraints.jl index 1d109d77d8..60bd72ece9 100644 --- a/src/Utilities/struct_of_constraints.jl +++ b/src/Utilities/struct_of_constraints.jl @@ -374,8 +374,9 @@ function struct_of_constraint_code(struct_name, types, field_types = nothing) # Here we make an internal constructor for our type. It needs to be an # internal constructor to avoid someone trying to provide # `typed_struct(args...)` which will throw an error about `T not defined`. + nothings = fill(nothing, length(field_types)) constructor_code = :(function $typed_struct() where {$T} - return new{$T}(0, $([:(nothing) for _ in field_types]...)) + return new{$T}(0, $(nothings...)) end) if type_parametrized # A bit confusing: we need to add the extra type parameters to `{T}`. diff --git a/src/sets.jl b/src/sets.jl index b321c0e65b..c1f0936034 100644 --- a/src/sets.jl +++ b/src/sets.jl @@ -1815,8 +1815,9 @@ function Base.getproperty( f::Symbol, ) if f == :side_dimension - return getproperty(set.set, f) + return getproperty(getfield(set, :set), f) else + @assert f == :set return getfield(set, f) end end diff --git a/test/Utilities/matrix_of_constraints.jl b/test/Utilities/matrix_of_constraints.jl index 275e0aa72f..02e5669984 100644 --- a/test/Utilities/matrix_of_constraints.jl +++ b/test/Utilities/matrix_of_constraints.jl @@ -630,6 +630,11 @@ function test_empty_product_of_sets(T = Int) return end +function test_set_types_fallback() + @test_throws MethodError MOI.Utilities.set_types(1) + return +end + end TestMatrixOfConstraints.runtests()