Skip to content

Commit

Permalink
Fix missing metadata fro + * with args containing metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenszhu committed Aug 12, 2024
1 parent 2ec473e commit 6d89149
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6d89149

Please sign in to comment.