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

Local indices in macros are not given gensym'd names #2186

Closed
odow opened this issue Mar 2, 2020 · 1 comment
Closed

Local indices in macros are not given gensym'd names #2186

odow opened this issue Mar 2, 2020 · 1 comment

Comments

@odow
Copy link
Member

odow commented Mar 2, 2020

A user contacted me with the following "feature." It's not clear what we should do, or how hard it would be to fix, but the error message is very unhelpful.

Potentially, the macros could look at the indices and compare against the model symbol?

model = Model()
@variable(model, x[model = 1:10] >= 1)

# results in

ERROR: MethodError: no method matching add_variable(::Int64, ::ScalarVariable{Int64,Float64,Float64,Float64}, ::String)
Closest candidates are:
  add_variable(::Model, ::ScalarVariable, ::String) at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/variables.jl:792
  add_variable(::Model, ::ScalarVariable) at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/variables.jl:792
  add_variable(::Model, ::VariableConstrainedOnCreation, ::String) at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/variables.jl:857
  ...
Stacktrace:
 [1] (::getfield(Main, Symbol("##13#14")))(::Int64) at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/Containers/macro.jl:183
 [2] (::getfield(JuMP.Containers, Symbol("##26#27")){getfield(Main, Symbol("##13#14"))})(::Tuple{Int64}) at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/Containers/container.jl:70
 [3] iterate at ./generator.jl:47 [inlined]
 [4] collect(::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Base.OneTo{Int64}}},getfield(JuMP.Containers, Symbol("##26#27")){getfield(Main, Symbol("##13#14"))}}) at ./array.jl:606
 [5] map(::Function, ::JuMP.Containers.VectorizedProductIterator{Tuple{Base.OneTo{Int64}}}) at ./abstractarray.jl:2044
 [6] container at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/Containers/container.jl:70 [inlined]
 [7] container(::Function, ::JuMP.Containers.VectorizedProductIterator{Tuple{Base.OneTo{Int64}}}) at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/Containers/container.jl:65
 [8] top-level scope at /Users/oscar/.julia/packages/JuMP/CZ8vV/src/macros.jl:79

This is also a problem in constraints as well

model = Model()
@variable(model, x[1:10])
@constraint(model, [model = 1:10], x[model] <= 1)
@mlubin
Copy link
Member

mlubin commented Sep 7, 2020

This is a duplicate of #858.

@mlubin mlubin closed this as completed Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants