diff --git a/src/types.jl b/src/types.jl index 7acff620f..a7b095570 100644 --- a/src/types.jl +++ b/src/types.jl @@ -588,13 +588,13 @@ function basicsymbolic(f, args, stype, metadata) elseif all(x->symtype(x) <: Number, args) if f === (+) res = +(args...) - if isadd(res) + if isadd(res) || isterm(res) @set! res.metadata = metadata end res elseif f == (*) res = *(args...) - if ismul(res) + if ismul(res) || isterm(res) @set! res.metadata = metadata end res diff --git a/test/basics.jl b/test/basics.jl index 20d772804..7d3457ae2 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -227,6 +227,20 @@ end # test that maketerm sets metadata correctly metadata = Base.ImmutableDict{DataType, Any}(Ctx1, "meta_1") + metadata2 = Base.ImmutableDict{DataType, Any}(Ctx2, "meta_2") + + @set! c.metadata = metadata2 + + s = SymbolicUtils.maketerm(typeof(a + b), +, [a * b, c], metadata) + @test isterm(s) + @test hasmetadata(s, Ctx1) + @test getmetadata(s, Ctx1) == "meta_1" + + s = SymbolicUtils.maketerm(typeof(a * b), *, [a * b, c], metadata) + @test isterm(s) + @test hasmetadata(s, Ctx1) + @test getmetadata(s, Ctx1) == "meta_1" + s = SymbolicUtils.maketerm(typeof(a^b), ^, [a * b, 3], metadata) @test !hasmetadata(s, Ctx1)