Skip to content

Commit a81f234

Browse files
authored
Merge pull request #632 from JuliaSymbolics/fix-basicsymbolic-drop-metadata
Fix missing `metadata` when operation and resulting `BasicSymbolic` subtype mismatch
2 parents 2ec473e + d8327c0 commit a81f234

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,13 @@ function basicsymbolic(f, args, stype, metadata)
588588
elseif all(x->symtype(x) <: Number, args)
589589
if f === (+)
590590
res = +(args...)
591-
if isadd(res)
591+
if isadd(res) || isterm(res)
592592
@set! res.metadata = metadata
593593
end
594594
res
595595
elseif f == (*)
596596
res = *(args...)
597-
if ismul(res)
597+
if ismul(res) || isterm(res)
598598
@set! res.metadata = metadata
599599
end
600600
res

test/basics.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,21 @@ end
227227

228228
# test that maketerm sets metadata correctly
229229
metadata = Base.ImmutableDict{DataType, Any}(Ctx1, "meta_1")
230+
metadata2 = Base.ImmutableDict{DataType, Any}(Ctx2, "meta_2")
231+
232+
d = b * c
233+
@set! d.metadata = metadata2
234+
235+
s = SymbolicUtils.maketerm(typeof(a + d), +, [a, d], metadata)
236+
@test isterm(s)
237+
@test hasmetadata(s, Ctx1)
238+
@test getmetadata(s, Ctx1) == "meta_1"
239+
240+
s = SymbolicUtils.maketerm(typeof(a * d), *, [a, d], metadata)
241+
@test isterm(s)
242+
@test hasmetadata(s, Ctx1)
243+
@test getmetadata(s, Ctx1) == "meta_1"
244+
230245
s = SymbolicUtils.maketerm(typeof(a^b), ^, [a * b, 3], metadata)
231246
@test !hasmetadata(s, Ctx1)
232247

0 commit comments

Comments
 (0)