Skip to content

Commit cdd0216

Browse files
committed
Fix metadata prop
`-(-x)` will simplify back to `x` and setting metadata on the simplified result is illegal.
1 parent 907fd5f commit cdd0216

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/types.jl

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,38 @@ function basicsymbolic(f, args, stype, metadata)
553553
T = _promote_symtype(f, args)
554554
end
555555
if T <: LiteralReal
556-
Term{T}(f, args, metadata=metadata)
557-
elseif T <: Number && (f in (+, *) || (f in (/, ^) && length(args) == 2)) && all(x->symtype(x) <: Number, args)
558-
res = f(args...)
559-
if res isa Symbolic
560-
@set! res.metadata = metadata
556+
@goto FALLBACK
557+
elseif all(x->symtype(x) <: Number, args)
558+
if f === (+)
559+
res = +(args...)
560+
if isadd(res)
561+
@set! res.metadata = metadata
562+
end
563+
res
564+
elseif f == (*)
565+
res = *(args...)
566+
if ismul(res)
567+
@set! res.metadata = metadata
568+
end
569+
res
570+
elseif f == (/)
571+
@assert length(args) == 2
572+
res = args[1] / args[2]
573+
if isdiv(res)
574+
@set! res.metadata = metadata
575+
end
576+
res
577+
elseif f == (^) && length(args) == 2
578+
res = args[1] ^ args[2]
579+
if ispow(res)
580+
@set! res.metadata = metadata
581+
end
582+
res
583+
else
584+
@goto FALLBACK
561585
end
562-
return res
563586
else
587+
@label FALLBACK
564588
Term{T}(f, args, metadata=metadata)
565589
end
566590
end

0 commit comments

Comments
 (0)