diff --git a/src/macros/@constraint.jl b/src/macros/@constraint.jl index 87d1e47726b..9789971cbe6 100644 --- a/src/macros/@constraint.jl +++ b/src/macros/@constraint.jl @@ -417,6 +417,25 @@ function parse_constraint_head(error_fn::Function, ::Val{T}, args...) where {T} ) end +function parse_constraint_head( + error_fn::Function, + ::Union{Val{:vect},Val{:vcat}}, + args..., +) + return error_fn( + """ + Unsupported constraint expression: we don't know how to parse a + `[ ]` block as a constraint. Have you written: + ```julia + @constraint(model, name, [...], ...) + ``` + instead of: + ```julia + @constraint(model, name[...], ...) + ```""", + ) +end + function parse_constraint_head( error_fn::Function, ::Val{:call}, diff --git a/test/test_macros.jl b/test/test_macros.jl index 6b559667f22..bb80c711579 100644 --- a/test/test_macros.jl +++ b/test/test_macros.jl @@ -2407,4 +2407,40 @@ function test_unsupported_name_syntax_multiple_ref() return end +function test_constraint_vect_vcat() + model = Model() + @variable(model, x) + @test_throws_parsetime( + ErrorException( + """ + In `@constraint(model, c, [k in 1:2], x <= k)`: Unsupported constraint expression: we don't know how to parse a + `[ ]` block as a constraint. Have you written: + ```julia + @constraint(model, name, [...], ...) + ``` + instead of: + ```julia + @constraint(model, name[...], ...) + ```""", + ), + @constraint(model, c, [k in 1:2], x <= k), + ) + @test_throws_parsetime( + ErrorException( + """ + In `@constraint(model, c, [k in 1:2; isodd(k)], x <= k)`: Unsupported constraint expression: we don't know how to parse a + `[ ]` block as a constraint. Have you written: + ```julia + @constraint(model, name, [...], ...) + ``` + instead of: + ```julia + @constraint(model, name[...], ...) + ```""", + ), + @constraint(model, c, [k in 1:2; isodd(k)], x <= k), + ) + return +end + end # module