From 6f5148a58a55679688917bb41381be2212ad2d19 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Wed, 17 Jul 2024 16:30:07 -0400 Subject: [PATCH] Fix metadata prop `-(-x)` will simplify back to `x` and setting metadata on the simplified result is illegal. --- src/types.jl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/types.jl b/src/types.jl index ba14e34f4..8830c3a1e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -553,16 +553,23 @@ function basicsymbolic(f, args, stype, metadata) T = _promote_symtype(f, args) end if T <: LiteralReal - Term{T}(f, args, metadata=metadata) - elseif T <: Number && (f in (+, *) || (f in (/, ^) && length(args) == 2)) && all(x->symtype(x) <: Number, args) - res = f(args...) - if res isa Symbolic - @set! res.metadata = metadata + @goto FALLBACK + elseif all(x->symtype(x) <: Number, args) + if f === (+) + Add(T, makeadd(1, 0, args...)...; metadata=metadata) + elseif f == (*) + Mul(T, makemul(1, args...)...; metadata=metadata) + elseif f == (/) + @assert length(args) == 2 + Div{T}(args...; metadata=metadata) + elseif f == (^) && length(args) == 2 + Pow{T}(makepow(args...)...; metadata=metadata) + else + @goto FALLBACK end - return res - else - Term{T}(f, args, metadata=metadata) end + @label FALLBACK + Term{T}(f, args, metadata=metadata) end ###