diff --git a/src/systems/callbacks.jl b/src/systems/callbacks.jl index c94166103b..348b7b09ec 100644 --- a/src/systems/callbacks.jl +++ b/src/systems/callbacks.jl @@ -438,8 +438,11 @@ function SymbolicDiscreteCallback( condition::Union{Symbolic{Bool}, Number, Vector{<:Number}}, affect = nothing; initialize = nothing, finalize = nothing, reinitializealg = nothing, kwargs...) - c = is_timed_condition(condition) ? condition : value(scalarize(condition)) + # Manual error check (to prevent events like `[X < 5.0] => [X ~ Pre(X) + 10.0]` from being created). + (condition isa Vector) && (eltype(condition) <: Num) && + error("Vectors of symbolic conditions are not allowed for `SymbolicDiscreteCallback`.") + c = is_timed_condition(condition) ? condition : value(scalarize(condition)) if isnothing(reinitializealg) if any(a -> a isa ImperativeAffect, [affect, initialize, finalize]) diff --git a/test/symbolic_events.jl b/test/symbolic_events.jl index 5f37e524e1..acf21bc361 100644 --- a/test/symbolic_events.jl +++ b/test/symbolic_events.jl @@ -1440,3 +1440,18 @@ end @mtkcompile sys = MWE() @test_nowarn ODEProblem(sys, [], (0.0, 1.0)) end + +@testset "Test erroneously created events yields errors" begin + @parameters p(t) d + @variables X(t) + @test_throws "Vectors of symbolic conditions are not allowed" SymbolicDiscreteCallback([X < + 5.0] => [X ~ + Pre(X) + + 10.0]) + @test_throws "Vectors of symbolic conditions are not allowed" SymbolicDiscreteCallback([ + X < 5.0, X > 10.0] => [X ~ Pre(X) + 10.0]) + @test_throws "MethodError: no method" SymbolicContinuousCallback((X < + 5.0) => [X ~ + Pre(X) + + 10.0]) +end