Skip to content

Commit 4647656

Browse files
committed
Bounds check hash, and fix some cases where states is a Vector{Any} instead of a Vector{BasicSymbolic{Real}}.
1 parent 7b8b266 commit 4647656

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/systems/abstractsystem.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,17 @@ end
631631
function states(sys::AbstractSystem)
632632
sts = get_states(sys)
633633
systems = get_systems(sys)
634-
unique(isempty(systems) ?
635-
sts :
636-
[sts; reduce(vcat, namespace_variables.(systems))])
634+
nonunique_states = if isempty(systems)
635+
sts
636+
else
637+
system_states = reduce(vcat, namespace_variables.(systems))
638+
isempty(sts) ? system_states : [sts; system_states]
639+
end
640+
# `Vector{Any}` is incompatible with the `SymbolicIndexingInterface`, which uses
641+
# `elsymtype = symbolic_type(eltype(_arg))`
642+
# which inappropriately returns `NotSymbolic()`
643+
@assert typeof(nonunique_states) !== Vector{Any}
644+
unique(nonunique_states)
637645
end
638646

639647
function parameters(sys::AbstractSystem)

src/systems/connectors.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,14 @@ Base.isequal(l1::ConnectionElement, l2::ConnectionElement) = l1 == l2
162162
function Base.:(==)(l1::ConnectionElement, l2::ConnectionElement)
163163
nameof(l1.sys) == nameof(l2.sys) && isequal(l1.v, l2.v) && l1.isouter == l2.isouter
164164
end
165-
Base.hash(e::ConnectionElement, salt::UInt) = e.h salt
165+
function Base.hash(e::ConnectionElement, salt::UInt)
166+
@inbounds begin
167+
@boundscheck begin
168+
@assert e.h === _hash_impl(e.sys, e.v, e.isouter)
169+
end
170+
end
171+
e.h salt
172+
end
166173
namespaced_var(l::ConnectionElement) = states(l, l.v)
167174
states(l::ConnectionElement, v) = states(copy(l.sys), v)
168175

0 commit comments

Comments
 (0)