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

Throw informative error when parsing reference sets in macros #3653

Closed odow closed 8 months ago

odow commented 8 months ago

Closes #3652

Error from #3652 is now:

julia> using JuMP

julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(model, a, Int)
a

julia> @variable(model, b[1:a], Int) 
ERROR: At REPL[67]:1: `@variable(model, b[1:a], Int)`: unexpected error parsing reference set: 1:a
Stacktrace:
 [1] error(::String, ::String, ::Expr)
   @ Base ./error.jl:44
 [2] (::JuMP.Containers.var"#error_fn#98"{String})(::String, ::Vararg{Any})
   @ JuMP.Containers ~/.julia/dev/JuMP/src/Containers/macro.jl:315
 [3] macro expansion
   @ ~/.julia/dev/JuMP/src/Containers/macro.jl:92 [inlined]
 [4] macro expansion
   @ ~/.julia/dev/JuMP/src/macros.jl:375 [inlined]
 [5] top-level scope
   @ REPL[67]:1

caused by: MethodError: no method matching (::Colon)(::Int64, ::VariableRef)

Closest candidates are:
  (::Colon)(::T, ::Any, ::T) where T<:Real
   @ Base range.jl:50
  (::Colon)(::A, ::Any, ::C) where {A<:Real, C<:Real}
   @ Base range.jl:10
  (::Colon)(::T, ::Any, ::T) where T
   @ Base range.jl:49
  ...

Stacktrace:
 [1] macro expansion
   @ ~/.julia/dev/JuMP/src/Containers/macro.jl:90 [inlined]
 [2] macro expansion
   @ ~/.julia/dev/JuMP/src/macros.jl:375 [inlined]
 [3] top-level scope
   @ REPL[67]:1

cc @LebedevRI

LebedevRI commented 8 months ago

Nice! Thank you!

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (b026f67) 98.28% compared to head (f90845f) 98.28%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #3653 +/- ## ======================================= Coverage 98.28% 98.28% ======================================= Files 43 43 Lines 5640 5650 +10 ======================================= + Hits 5543 5553 +10 Misses 97 97 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.