Skip to content

Commit

Permalink
Fix metadata prop
Browse files Browse the repository at this point in the history
`-(-x)` will simplify back to `x` and setting metadata on the simplified result
is illegal.
  • Loading branch information
YingboMa committed Jul 17, 2024
1 parent 907fd5f commit 6f5148a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

###
Expand Down

0 comments on commit 6f5148a

Please sign in to comment.