From 225fb55b9971ef653847632c25b7c73cf39eb47a Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Tue, 11 Feb 2025 12:17:30 +0100 Subject: [PATCH] Do not attempt to promote to Union Sometimes `symtype` returns a union like `Union{Float64, Int64}` ```julia julia> @variables x::Float64 1-element Vector{Num}: x julia> ModelingToolkit.symtype(ifelse(x > 0, x, 0)) Union{Float64, Int64} ``` and then ```julia buf = get!(() -> Any[], cachevars, T) ``` fails. This is (very) likely to occur with JSML, which appears to type things with `Float64` --- src/systems/nonlinear/nonlinearsystem.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/systems/nonlinear/nonlinearsystem.jl b/src/systems/nonlinear/nonlinearsystem.jl index b5256ca4ca..c211d02780 100644 --- a/src/systems/nonlinear/nonlinearsystem.jl +++ b/src/systems/nonlinear/nonlinearsystem.jl @@ -712,6 +712,9 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map, k = unwrap(k) v = unwrap(v) T = symtype(k) + while T isa Union + T = promote_type(T.a, T.b) + end buf = get!(() -> Any[], cachevars, T) push!(buf, v) buf = get!(() -> Any[], cacheexprs, T)