Skip to content

Commit

Permalink
Fix broadcasting f-in-set in constraint macro (#3632)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Dec 18, 2023
1 parent 2c97ecc commit 817dc13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/macros/@constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ function parse_constraint_call(
)
f, parse_code = _rewrite_expression(func)
build_call = if vectorized
:(build_constraint.($error_fn, _desparsify($f), Ref($(esc(set)))))
:(build_constraint.($error_fn, _desparsify($f), $(esc(set))))
else
:(build_constraint($error_fn, $f, $(esc(set))))
end
Expand Down
13 changes: 13 additions & 0 deletions test/test_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2210,4 +2210,17 @@ function test_base_name_escape()
return
end

function test_constraint_broadcast_in_set()
model = Model()
@variable(model, x[1:2])
sets = [MOI.GreaterThan(1.0), MOI.GreaterThan(2.0)]
c = @constraint(model, 1.0 * x .∈ sets)
@test constraint_object(c[1]).set == MOI.GreaterThan(1.0)
@test constraint_object(c[2]).set == MOI.GreaterThan(2.0)
c = @constraint(model, 1.0 * x .∈ MOI.ZeroOne())
@test constraint_object(c[1]).set == MOI.ZeroOne()
@test constraint_object(c[2]).set == MOI.ZeroOne()
return
end

end # module

0 comments on commit 817dc13

Please sign in to comment.