Skip to content

Commit

Permalink
Improve detection of writeback values
Browse files Browse the repository at this point in the history
  • Loading branch information
BenChung committed Sep 24, 2024
1 parent e6bdd12 commit 9eb5389
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,18 @@ end
return :(begin $(setter_exprs...) end)
end

function check_assignable(sys, sym)
if symbolic_type(sym) == ScalarSymbolic()
is_variable(sys, sym) || is_parameter(sys, sym)
elseif symbolic_type(sym) == ArraySymbolic()
is_variable(sys, sym) || is_parameter(sys, sym) || all(x -> check_assignable(sys, x), collect(sym))
elseif sym isa Union{AbstractArray, Tuple}
all(x -> check_assignable(sys, x), sym)
else
false
end
end

function compile_user_affect(affect::MutatingFunctionalAffect, cb, sys, dvs, ps; kwargs...)
#=
Implementation sketch:
Expand Down Expand Up @@ -1038,7 +1050,7 @@ function compile_user_affect(affect::MutatingFunctionalAffect, cb, sys, dvs, ps;
mod_exprs = modified(affect)
if !affect.skip_checks
for mexpr in mod_exprs
if !is_variable(sys, mexpr) && parameter_index(sys, mexpr) === nothing
if !check_assignable(sys, mexpr)
@warn ("Expression $mexpr cannot be assigned to; currently only unknowns and parameters may be updated by an affect.")
end
invalid_vars = unassignable_variables(sys, mexpr)
Expand Down

0 comments on commit 9eb5389

Please sign in to comment.