JuMP @constraint macro modifies existing expression

I have encountered cases where JuMP will modify an expression if it is used in a constraint. This seems like undesirable behavior, as the expression could be used later thinking it is the same as the original. Here is a minimum working example:

julia> using JuMP
julia> model = Model();

julia> @variable(model, 0 <= x <= 5);

julia> @expression(model, e, x + 5)
x + 5

julia> @constraint(model, -10 <= e <= 10)
x in [-15, 5]

julia> e
1 Like

Ouch! This is a nasty bug: Constraint macro modifies expression · Issue #3638 · jump-dev/JuMP.jl · GitHub

I’ll take a look.

Edit: fix in-bound: Fix modifying user-expressions in macros by odow · Pull Request #3639 · jump-dev/JuMP.jl · GitHub

1 Like