Skip to content

Commit

Permalink
Fix various JET errors (#2289)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 22, 2023
1 parent 9893e0b commit aff9f0f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/bridges/set_dot_scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions src/Utilities/matrix_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Utilities/struct_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}`.
Expand Down
3 changes: 2 additions & 1 deletion src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/Utilities/matrix_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit aff9f0f

Please sign in to comment.