Skip to content

Commit 7fa4324

Browse files
fix: fix @mtkbuild macro keyword parsing
1 parent 387df59 commit 7fa4324

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/systems/abstractsystem.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,15 +2248,20 @@ macro mtkbuild(exprs...)
22482248
expr = exprs[1]
22492249
named_expr = ModelingToolkit.named_expr(expr)
22502250
name = named_expr.args[1]
2251-
kwargs = if length(exprs) > 1
2252-
NamedTuple{Tuple(ex.args[1] for ex in Base.tail(exprs))}(Tuple(ex.args[2]
2253-
for ex in Base.tail(exprs)))
2251+
kwargs = Base.tail(exprs)
2252+
kwargs = map(kwargs) do ex
2253+
@assert ex.head == :(=)
2254+
Expr(:kw, ex.args[1], ex.args[2])
2255+
end
2256+
if isempty(kwargs)
2257+
kwargs = ()
22542258
else
2255-
(;)
2259+
kwargs = (Expr(:parameters, kwargs...),)
22562260
end
2261+
call_expr = Expr(:call, structural_simplify, kwargs..., name)
22572262
esc(quote
22582263
$named_expr
2259-
$name = $structural_simplify($name; $(kwargs)...)
2264+
$name = $call_expr
22602265
end)
22612266
end
22622267

test/if_lifting.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,17 @@ end
110110
@test operation(eq.rhs) === ifelse
111111
end
112112
end
113+
114+
@testset "`@mtkbuild` macro accepts `additional_passes`" begin
115+
@mtkmodel SimpleAbs begin
116+
@variables begin
117+
x(t)
118+
y(t)
119+
end
120+
@equations begin
121+
D(x) ~ abs(y)
122+
y ~ sin(t)
123+
end
124+
end
125+
@test_nowarn @mtkbuild sys=SimpleAbs() additional_passes=[IfLifting]
126+
end

0 commit comments

Comments
 (0)