Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@variable macro fails to resolve variables in 1.18.0 #3646

Closed
ianfiske opened this issue Jan 5, 2024 · 2 comments · Fixed by #3647
Closed

@variable macro fails to resolve variables in 1.18.0 #3646

ianfiske opened this issue Jan 5, 2024 · 2 comments · Fixed by #3647

Comments

@ianfiske
Copy link
Contributor

ianfiske commented Jan 5, 2024

Here's a MWE:

using JuMP

m = Model()
x = (lower_bound=5.0,)
@variable(m, set = MOI.GreaterThan(x.lower_bound))

With JuMP 1.18.0, this fails with the error

ERROR: UndefVarError: `x` not defined
Stacktrace:
 [1] macro expansion
   @ ~/.julia/packages/JuMP/9tYtW/src/macros/@variable.jl:313 [inlined]
 [2] macro expansion
   @ ~/.julia/packages/JuMP/9tYtW/src/macros.jl:375 [inlined]
 [3] top-level scope
   @ ~/julia-envs/jump-bug/minrepro.jl:6

In JuMP 1.17 and below, there is no error.

@odow
Copy link
Member

odow commented Jan 5, 2024

I'll take a look. I recently refactored our macro handling, so this is my fault.

I guess I was right #3629 (comment)

The main risk is probably esc scoping bugs

@odow
Copy link
Member

odow commented Jan 5, 2024

See #3647

I guess the lesson is that when writing tests, we should prefer to use variables rather than literals so that we can check for scoping bugs like this.

@odow odow closed this as completed in #3647 Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants