diff --git a/src/Containers/macro.jl b/src/Containers/macro.jl index 7b2322b532b..b20c6a76743 100644 --- a/src/Containers/macro.jl +++ b/src/Containers/macro.jl @@ -170,7 +170,13 @@ function _parse_ref_sets(error_fn::Function, expr::Expr) # `:(t[i, j; k])` is a `:ref`, while `:(t[i; j])` is a `:typed_vcat`. In # both cases `:t` is the first argument. if Meta.isexpr(c, :typed_vcat) || Meta.isexpr(c, :ref) - popfirst!(c.args) + name = popfirst!(c.args) + if !(name isa Symbol) + error_fn( + "Unsupported syntax: the expression `$name` cannot be used " * + "as a name.", + ) + end end if Meta.isexpr(c, :vcat) || Meta.isexpr(c, :typed_vcat) # An expression like `t[i; k]` or `[i; k]`. The filtering condition is diff --git a/test/test_macros.jl b/test/test_macros.jl index 2321b8deaf9..d1a7f8dd9e3 100644 --- a/test/test_macros.jl +++ b/test/test_macros.jl @@ -2395,4 +2395,16 @@ function test_force_nonlinear() return end +function test_unsupported_name_syntax_multiple_ref() + model = Model() + @test_throws_parsetime( + ErrorException( + "In `@variable(model, (x[1:1])[1:2])`: Unsupported syntax: " * + "the expression `x[1:1]` cannot be used as a name.", + ), + @variable(model, x[1:1][1:2]), + ) + return +end + end # module