@@ -141,20 +141,19 @@ function IndexCache(sys::AbstractSystem)
141141 error (" Unhandled affect type $(typeof (affect)) " )
142142 end
143143 end
144-
145144 for sym in discs
146145 if ! is_parameter (sys, sym)
147- if iscall (sym) && operation (sym) === getindex &&
148- is_parameter (sys, arguments (sym)[ 1 ] )
149- sym = arguments (sym)[ 1 ]
146+ arr, isarr = split_indexed_var (sym)
147+ if isarr && is_parameter (sys, arr )
148+ sym = arr
150149 else
151150 error (" Expected discrete variable $sym in callback to be a parameter" )
152151 end
153152 end
154153
155154 # Only `foo(t)`-esque parameters can be saved
156- if iscall (sym) && length (arguments (sym)) == 1 &&
157- isequal (only (arguments (sym)), get_iv (sys))
155+ if iscall (sym) && ( operation (sym) isa Union{Operator, BasicSymbolic} || length (arguments (sym)) == 1 &&
156+ isequal (only (arguments (sym)), get_iv (sys)))
158157 clocks = get! (() -> Set {Int} (), disc_param_callbacks, sym)
159158 push! (clocks, i)
160159 elseif is_variable_floatingpoint (sym)
@@ -414,6 +413,22 @@ function IndexCache(sys::AbstractSystem)
414413 )
415414end
416415
416+ function split_indexed_var (x)
417+ iscall (x) || return (x, false )
418+ f = operation (x)
419+ args = arguments (x)
420+ if f === getindex
421+ return args[1 ], true
422+ end
423+ if f isa Operator && length (args) == 1
424+ arr, isarr = split_indexed_var (args[1 ])
425+ isarr || return x, false
426+ return f (arr), isarr
427+ end
428+ return x, false
429+ end
430+
431+
417432function SymbolicIndexingInterface. is_variable (ic:: IndexCache , sym)
418433 variable_index (ic, sym) != = nothing
419434end
0 commit comments