Skip to content

Commit b052bf2

Browse files
authored
Merge pull request #698 from mimiframework/rename
using renamed components in #defcomposite
2 parents 5d5498b + 41fee79 commit b052bf2

File tree

3 files changed

+31
-70
lines changed

3 files changed

+31
-70
lines changed

src/core/defcomposite.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ function _parse(expr)
109109

110110
elseif @capture(arg, (cname_.pname_ | pname_))
111111
cname = (cname === nothing ? :(:*) : cname) # wildcard
112-
push!(regargs, :($cname => $(QuoteNode(pname))))
112+
push!(regargs, :(obj[$(QuoteNode(cname))] => $(QuoteNode(pname))))
113+
113114
end
114115
end
115116
result = :(Mimi.import_param!(obj, $(QuoteNode(localparname)), $(regargs...);

test/test_composite.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,35 @@ path1 = ComponentPath(:a, :b)
175175
path2 = ComponentPath(:c, :d)
176176
@test ComponentPath(path1, path2) == ComponentPath(:a, :b, :c, :d)
177177

178+
# renaming
179+
180+
@defcomp A begin
181+
p1 = Parameter()
182+
p2 = Parameter()
183+
184+
v1 = Variable()
185+
end
186+
187+
@defcomp B begin
188+
v2 = Variable()
189+
end
190+
191+
@defcomposite C begin
192+
193+
foo = Component(A)
194+
bar = Component(B)
195+
196+
rename_p1 = Parameter(foo.p1)
197+
198+
connect(foo.p2, bar.v2)
199+
200+
rename_v1 = Variable(foo.v1)
201+
end
202+
203+
for key in [:foo, :bar, :rename_p1, :rename_v1]
204+
@test key in keys(C.namespace)
205+
end
206+
178207
end # module
179208

180209
nothing

test/test_defcomposite.jl

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)