Skip to content

fix: fix getproperty syntax on structural_simplify(complete(sys)) #3203

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 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ function Base.propertynames(sys::AbstractSystem; private = false)
return fieldnames(typeof(sys))
else
if has_parent(sys) && (parent = get_parent(sys); parent !== nothing)
sys = parent
return propertynames(parent; private)
end
names = Symbol[]
for s in get_systems(sys)
Expand All @@ -1144,7 +1144,7 @@ end

function Base.getproperty(sys::AbstractSystem, name::Symbol; namespace = !iscomplete(sys))
if has_parent(sys) && (parent = get_parent(sys); parent !== nothing)
sys = parent
return getproperty(parent, name; namespace)
end
wrap(getvar(sys, name; namespace = namespace))
end
Expand Down
20 changes: 20 additions & 0 deletions test/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,23 @@ end
@test_throws ArgumentError simp.inner₊p
@test_throws ArgumentError outer.inner₊p
end

@testset "`getproperty` on `structural_simplify(complete(sys))`" begin
@mtkmodel Foo begin
@variables begin
x(t)
end
end
@mtkmodel Bar begin
@components begin
foo = Foo()
end
@equations begin
D(foo.x) ~ foo.x
end
end
@named bar = Bar()
cbar = complete(bar)
ss = structural_simplify(cbar)
@test isequal(cbar.foo.x, ss.foo.x)
end
Loading