diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index 59d1f23406..36a3d1a124 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -964,7 +964,7 @@ function _named(name, call, runtime = false) if length(call.args) >= 2 && call.args[2] isa Expr # canonicalize to use `:parameters` if call.args[2].head === :kw - call.args[2] = Expr(:parameters, Expr(:kw, call.args[2].args...)) + call = Expr(call.head, call.args[1], Expr(:parameters, call.args[2:end]...)) has_kw = true elseif call.args[2].head === :parameters has_kw = true diff --git a/test/direct.jl b/test/direct.jl index fde52fb2b4..ec1ef23980 100644 --- a/test/direct.jl +++ b/test/direct.jl @@ -2,6 +2,8 @@ using ModelingToolkit, StaticArrays, LinearAlgebra, SparseArrays using DiffEqBase using Test +using ModelingToolkit: getdefault, getmetadata, SymScope + canonequal(a, b) = isequal(simplify(a), simplify(b)) # Calculus @@ -271,3 +273,35 @@ end @parameters x [misc = "wow"] @test SymbolicUtils.getmetadata(Symbolics.unwrap(x), ModelingToolkit.VariableMisc, nothing) == "wow" + +# Scope of defaults in the systems generated by @named +@mtkmodel LevelThree begin + @variables begin + x(t) + y(t) + z(t) + end +end + +@mtkmodel LevelTwo begin + @parameters begin + l + m + n + end + @components begin + three = LevelThree(x = l, y = m, z = n) + end +end + +@mtkmodel LevelOne begin + @components begin + two = LevelTwo() + end +end + +@named one = LevelOne() + +@test getmetadata(getdefault(one.two.three.x), SymScope) == ParentScope(LocalScope()) +@test getmetadata(getdefault(one.two.three.y), SymScope) == ParentScope(LocalScope()) +@test getmetadata(getdefault(one.two.three.z), SymScope) == ParentScope(LocalScope())