Skip to content

Commit 1fcec41

Browse files
committed
feat: parity in symbolic-array definition with vanilla @variables
1 parent 6532774 commit 1fcec41

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/systems/model_parsing.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
264264
varclass, where_types, meta)
265265
return var, def, Dict()
266266
end
267+
Expr(:tuple, Expr(:(=), Expr(:ref, a, indices...), default_val), meta_val) ||
268+
Expr(:tuple, Expr(:(=), Expr(:(::), Expr(:ref, a, indices...), type), default_val), meta_val) ||
267269
Expr(:tuple, Expr(:(::), Expr(:ref, a, indices...), type), meta_val) ||
268270
Expr(:tuple, Expr(:ref, a, indices...), meta_val) => begin
269271
(@isdefined type) || (type = Real)

test/model_parsing.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,21 @@ end
279279
@test MockModel.structure[:defaults] == Dict(:n => 1.0, :n2 => "g()")
280280
end
281281

282+
@testset "Arrays using vanilla-@variable syntax" begin
283+
@mtkmodel TupleInArrayDef begin
284+
@parameters begin
285+
(l(t)[1:2, 1:3] = 1), [description = "l is more than 1D"]
286+
(l2(t)[1:3] = 2), [description = "l2 is 1D"]
287+
(l3(t)[1:3]::Int = 3), [description = "l3 is 1D and has a type"]
288+
end
289+
end
290+
291+
@named arr = TupleInArrayDef()
292+
@test getdefault(arr.l) == 1
293+
@test getdefault(arr.l2) == 2
294+
@test getdefault(arr.l3) == 3
295+
end
296+
282297
@testset "Type annotation" begin
283298
@mtkmodel TypeModel begin
284299
@structural_parameters begin

0 commit comments

Comments
 (0)