Skip to content

Commit 8efd0a4

Browse files
Merge pull request #2373 from ven-k/vkb/parameter-canon-in-at-named
fix: canonicalize all positional args in `@named`
2 parents 97b6524 + 65440fe commit 8efd0a4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ function _named(name, call, runtime = false)
964964
if length(call.args) >= 2 && call.args[2] isa Expr
965965
# canonicalize to use `:parameters`
966966
if call.args[2].head === :kw
967-
call.args[2] = Expr(:parameters, Expr(:kw, call.args[2].args...))
967+
call = Expr(call.head, call.args[1], Expr(:parameters, call.args[2:end]...))
968968
has_kw = true
969969
elseif call.args[2].head === :parameters
970970
has_kw = true

test/direct.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using ModelingToolkit, StaticArrays, LinearAlgebra, SparseArrays
22
using DiffEqBase
33
using Test
44

5+
using ModelingToolkit: getdefault, getmetadata, SymScope
6+
57
canonequal(a, b) = isequal(simplify(a), simplify(b))
68

79
# Calculus
@@ -271,3 +273,24 @@ end
271273
@parameters x [misc = "wow"]
272274
@test SymbolicUtils.getmetadata(Symbolics.unwrap(x), ModelingToolkit.VariableMisc,
273275
nothing) == "wow"
276+
277+
# Scope of defaults in the systems generated by @named
278+
@mtkmodel MoreThanOneArg begin
279+
@variables begin
280+
x(t)
281+
y(t)
282+
z(t)
283+
end
284+
end
285+
286+
@parameters begin
287+
l
288+
m
289+
n
290+
end
291+
292+
@named model = MoreThanOneArg(x = l, y = m, z = n)
293+
294+
@test getmetadata(getdefault(model.x), SymScope) == ParentScope(LocalScope())
295+
@test getmetadata(getdefault(model.y), SymScope) == ParentScope(LocalScope())
296+
@test getmetadata(getdefault(model.z), SymScope) == ParentScope(LocalScope())

0 commit comments

Comments
 (0)