Skip to content

Commit 9f4e7b8

Browse files
committed
feat: parity in symbolic-array definition with vanilla @variables
1 parent a403880 commit 9f4e7b8

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
@@ -270,6 +270,8 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
270270
varclass, where_types, meta)
271271
return var, def, Dict()
272272
end
273+
Expr(:tuple, Expr(:(=), Expr(:ref, a, indices...), default_val), meta_val) ||
274+
Expr(:tuple, Expr(:(=), Expr(:(::), Expr(:ref, a, indices...), type), default_val), meta_val) ||
273275
Expr(:tuple, Expr(:(::), Expr(:ref, a, indices...), type), meta_val) ||
274276
Expr(:tuple, Expr(:ref, a, indices...), meta_val) => begin
275277
(@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)