jump-dev / JuMP.jl

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)
http://jump.dev/JuMP.jl/
Other
2.22k stars 393 forks source link

Hygiene issue with indicator constraints #3812

Closed blegat closed 1 month ago

blegat commented 1 month ago
model = Model()
@variable(model, b, Bin)
@variable(model, x)
@constraint(model, b => {x in MOI.EqualTo(1.0)})

gives

ERROR: LoadError: UndefVarError: `##3910` not defined
Stacktrace:
 [1] macro expansion
   @ ~/.julia/packages/JuMP/W1IDA/src/macros/@constraint.jl:171 [inlined]
 [2] macro expansion
   @ ~/.julia/packages/JuMP/W1IDA/src/macros.jl:393 [inlined]

The hygiene seems ok if you do x == 1 but not with the in syntax

odow commented 1 month ago

Hmm. Yeah. I don't think we considered this, but we should throw a nicer error message.

odow commented 1 month ago

Simple fix: https://github.com/jump-dev/JuMP.jl/pull/3813