Skip to content

Commit f603e8c

Browse files
test: test @named always wrapping in ParentScope
1 parent 138c568 commit f603e8c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/odesystem.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using SymbolicUtils: issym
99
using ForwardDiff
1010
using ModelingToolkit: value
1111
using ModelingToolkit: t_nounits as t, D_nounits as D
12+
using Symbolics: unwrap
1213

1314
# Define some variables
1415
@parameters σ ρ β
@@ -1730,3 +1731,26 @@ end
17301731
@test obsfn_expr_oop isa Expr
17311732
@test obsfn_expr_iip isa Expr
17321733
end
1734+
1735+
@testset "`@named` always wraps in `ParentScope`" begin
1736+
function SysA(; name, var1)
1737+
@variables x(t)
1738+
scope = ModelingToolkit.getmetadata(unwrap(var1), ModelingToolkit.SymScope, nothing)
1739+
@test scope isa ParentScope
1740+
@test scope.parent isa ParentScope
1741+
@test scope.parent.parent isa LocalScope
1742+
return ODESystem(D(x) ~ var1, t; name)
1743+
end
1744+
function SysB(; name, var1)
1745+
@variables x(t)
1746+
@named subsys = SysA(; var1)
1747+
return ODESystem(D(x) ~ x, t; systems = [subsys], name)
1748+
end
1749+
function SysC(; name)
1750+
@variables x(t)
1751+
@named subsys = SysB(; var1 = x)
1752+
return ODESystem(D(x) ~ x, t; systems = [subsys], name)
1753+
end
1754+
@mtkbuild sys = SysC()
1755+
@test length(unknowns(sys)) == 3
1756+
end

0 commit comments

Comments
 (0)