Skip to content

Commit

Permalink
Merge pull request #2373 from ven-k/vkb/parameter-canon-in-at-named
Browse files Browse the repository at this point in the history
fix: canonicalize all positional args in `@named`
  • Loading branch information
ChrisRackauckas authored Dec 7, 2023
2 parents 97b6524 + 65440fe commit 8efd0a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/direct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -271,3 +273,24 @@ 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 MoreThanOneArg begin
@variables begin
x(t)
y(t)
z(t)
end
end

@parameters begin
l
m
n
end

@named model = MoreThanOneArg(x = l, y = m, z = n)

@test getmetadata(getdefault(model.x), SymScope) == ParentScope(LocalScope())
@test getmetadata(getdefault(model.y), SymScope) == ParentScope(LocalScope())
@test getmetadata(getdefault(model.z), SymScope) == ParentScope(LocalScope())

0 comments on commit 8efd0a4

Please sign in to comment.