Skip to content

Commit c09f075

Browse files
fix: fix stack overflow for methods using symbolic_container to define a fallback
1 parent a5be447 commit c09f075

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/index_provider_interface.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ parameter_index(indp, sym) = parameter_index(symbolic_container(indp), sym)
5959
Check whether the given `sym` is a timeseries parameter in `indp`.
6060
"""
6161
function is_timeseries_parameter(indp, sym)
62-
if hasmethod(symbolic_container, Tuple{typeof(indp)})
63-
is_timeseries_parameter(symbolic_container(indp), sym)
62+
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
63+
is_timeseries_parameter(sc, sym)
6464
else
6565
return false
6666
end
@@ -91,7 +91,7 @@ parameter in `indp`. Defaults to returning `nothing`. Respects the
9191
[`symbolic_container`](@ref) fallback for `indp` if present.
9292
"""
9393
function timeseries_parameter_index(indp, sym)
94-
if hasmethod(symbolic_container, Tuple{typeof(indp)})
94+
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
9595
timeseries_parameter_index(symbolic_container(indp), sym)
9696
else
9797
return nothing
@@ -111,7 +111,7 @@ By default, this function returns `nothing`, indicating that the index provider
111111
support generating parameter observed functions.
112112
"""
113113
function parameter_observed(indp, sym)
114-
if hasmethod(symbolic_container, Tuple{typeof(indp)})
114+
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
115115
return parameter_observed(symbolic_container(indp), sym)
116116
else
117117
return nothing
@@ -143,7 +143,7 @@ variable.
143143
By default, this function returns `Set([ContinuousTimeseries()])`.
144144
"""
145145
function get_all_timeseries_indexes(indp, sym)
146-
if hasmethod(symbolic_container, Tuple{typeof(indp)})
146+
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
147147
return get_all_timeseries_indexes(symbolic_container(indp), sym)
148148
else
149149
return Set([ContinuousTimeseries()])
@@ -240,7 +240,7 @@ Return a dictionary mapping symbols in the index provider to their default value
240240
This includes parameter symbols. The dictionary must be mutable.
241241
"""
242242
function default_values(indp)
243-
if hasmethod(symbolic_container, Tuple{typeof(indp)})
243+
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
244244
default_values(symbolic_container(indp))
245245
else
246246
Dict()

src/symbol_cache.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ function SymbolCache(vars = nothing, params = nothing, indepvars = nothing;
7171
defaults)
7272
end
7373

74+
symbolic_container(sc::SymbolCache) = sc
75+
7476
function is_variable(sc::SymbolCache, sym)
7577
sc.variables === nothing && return false
7678
if symbolic_type(sym) == NotSymbolic()

0 commit comments

Comments
 (0)