Skip to content

Commit 7224f5c

Browse files
Merge pull request #4750 from SciML/as/const-arg-of-op
fix: `Const` argument of operator is not considered a variable
2 parents 4a0de7f + 22e3982 commit 7224f5c

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/ModelingToolkitBase/src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ function collect_vars!(unknowns::OrderedSet{SymbolicT}, parameters::OrderedSet{S
846846
SU.search_variables!(vars, expr; is_atomic = OperatorIsAtomic{op}())
847847
for var in vars
848848
Moshi.Match.@match var begin
849+
BSImpl.Const() => nothing
849850
BSImpl.Term(; f, args) && if f isa op end => begin
850851
validate_operator(f, args, iv; context = expr)
851852
isempty(args) && continue

lib/ModelingToolkitBase/test/system_building.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ModelingToolkitBase
22
using ModelingToolkitBase: t_nounits as t, D_nounits as D
3+
import SymbolicUtils as SU
34

45
@testset "`state_priorities` and `irreducibles` kwargs take priority over metadata" begin
56
@variables x(t) [state_priority = 3] y(t) [irreducible = false]
@@ -62,3 +63,12 @@ end
6263
sys = ModelingToolkitBase.set_necessary_initial_conditions(sys, ics)
6364
@test_throws ModelingToolkitBase.MissingNecessaryInitialConditionsError ODEProblem(sys, [x => 1], (0.0, 1.0))
6465
end
66+
67+
struct MyOp <: SU.Operator end
68+
ModelingToolkitBase.validate_operator(::MyOp, args...; kws...) = nothing
69+
70+
@testset "Const argument of operator is not considered a variable" begin
71+
@variables x(t)
72+
@named sys = System([D(x) ~ x + SU.term(MyOp(), [0.0]; type = Real, shape = SU.ShapeVecT())], t)
73+
@test issetequal(unknowns(sys), [x])
74+
end

0 commit comments

Comments
 (0)