Skip to content

Commit 1768a9e

Browse files
Merge pull request #3567 from AayushSabharwal/as/named-always-parentscope
test: test `@named` always wrapping in `ParentScope`
2 parents dc97063 + 09f5ff0 commit 1768a9e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/odesystem.jl

+24
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 σ ρ β
@@ -1732,3 +1733,26 @@ end
17321733
@test obsfn_expr_oop isa Expr
17331734
@test obsfn_expr_iip isa Expr
17341735
end
1736+
1737+
@testset "`@named` always wraps in `ParentScope`" begin
1738+
function SysA(; name, var1)
1739+
@variables x(t)
1740+
scope = ModelingToolkit.getmetadata(unwrap(var1), ModelingToolkit.SymScope, nothing)
1741+
@test scope isa ParentScope
1742+
@test scope.parent isa ParentScope
1743+
@test scope.parent.parent isa LocalScope
1744+
return ODESystem(D(x) ~ var1, t; name)
1745+
end
1746+
function SysB(; name, var1)
1747+
@variables x(t)
1748+
@named subsys = SysA(; var1)
1749+
return ODESystem(D(x) ~ x, t; systems = [subsys], name)
1750+
end
1751+
function SysC(; name)
1752+
@variables x(t)
1753+
@named subsys = SysB(; var1 = x)
1754+
return ODESystem(D(x) ~ x, t; systems = [subsys], name)
1755+
end
1756+
@mtkbuild sys = SysC()
1757+
@test length(unknowns(sys)) == 3
1758+
end

0 commit comments

Comments
 (0)