Skip to content

test: test @named always wrapping in ParentScope #3567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using SymbolicUtils: issym
using ForwardDiff
using ModelingToolkit: value
using ModelingToolkit: t_nounits as t, D_nounits as D
using Symbolics: unwrap

# Define some variables
@parameters σ ρ β
Expand Down Expand Up @@ -1732,3 +1733,26 @@ end
@test obsfn_expr_oop isa Expr
@test obsfn_expr_iip isa Expr
end

@testset "`@named` always wraps in `ParentScope`" begin
function SysA(; name, var1)
@variables x(t)
scope = ModelingToolkit.getmetadata(unwrap(var1), ModelingToolkit.SymScope, nothing)
@test scope isa ParentScope
@test scope.parent isa ParentScope
@test scope.parent.parent isa LocalScope
return ODESystem(D(x) ~ var1, t; name)
end
function SysB(; name, var1)
@variables x(t)
@named subsys = SysA(; var1)
return ODESystem(D(x) ~ x, t; systems = [subsys], name)
end
function SysC(; name)
@variables x(t)
@named subsys = SysB(; var1 = x)
return ODESystem(D(x) ~ x, t; systems = [subsys], name)
end
@mtkbuild sys = SysC()
@test length(unknowns(sys)) == 3
end
Loading