Skip to content

Commit 084fbbf

Browse files
refactor: disable setproperty! on systems
1 parent d1bffda commit 084fbbf

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/systems/abstractsystem.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,19 +1074,14 @@ function getvar(sys::AbstractSystem, name::Symbol; namespace = does_namespacing(
10741074
end
10751075

10761076
function Base.setproperty!(sys::AbstractSystem, prop::Symbol, val)
1077-
# We use this weird syntax because `parameters` and `unknowns` calls are
1078-
# potentially expensive.
1079-
if (params = parameters(sys);
1080-
idx = findfirst(s -> getname(s) == prop, params);
1081-
idx !== nothing)
1082-
get_defaults(sys)[params[idx]] = value(val)
1083-
elseif (sts = unknowns(sys);
1084-
idx = findfirst(s -> getname(s) == prop, sts);
1085-
idx !== nothing)
1086-
get_defaults(sys)[sts[idx]] = value(val)
1087-
else
1088-
setfield!(sys, prop, val)
1089-
end
1077+
error("""
1078+
`setproperty!` on systems is invalid. Systems are immutable data structures, and \
1079+
modifications to fields should be made by constructing a new system. This can be done \
1080+
easily using packages such as Setfield.jl.
1081+
1082+
If you are looking for the old behavior of updating the default of a variable via \
1083+
`setproperty!`, this should now be done by mutating `ModelingToolkit.get_defaults(sys)`.
1084+
""")
10901085
end
10911086

10921087
apply_to_variables(f::F, ex) where {F} = _apply_to_variables(f, ex)

0 commit comments

Comments
 (0)