Skip to content

Commit 6f76a28

Browse files
Add test and fix branch in walk
1 parent f387fe6 commit 6f76a28

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/rewriters.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ function (rw::FixpointNoCycle)(x)
151151
f = rw.rw
152152
push!(rw.hist, hash(x))
153153
y = @timer cached_repr(f) f(x)
154-
while x !== y && hash(x) hist
155-
if y === nothing
154+
while x !== y && hash(x) rw.hist
155+
if y === nothing
156156
empty!(rw.hist)
157157
return x
158158
end
@@ -201,9 +201,10 @@ function (p::Walk{ord, C, F, false})(x) where {ord, C, F}
201201
if ord === :pre
202202
x = p.rw(x)
203203
end
204-
if istree(x)
205-
x = p.similarterm(x, operation(x), map(PassThrough(p), unsorted_arguments(x)), metadata=metadata(x))
206-
end
204+
205+
x = p.similarterm(x, operation(x), map(PassThrough(p),
206+
unsorted_arguments(x)), metadata=metadata(x))
207+
207208
return ord === :post ? p.rw(x) : x
208209
else
209210
return p.rw(x)

test/rewrite.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,19 @@ using SymbolicUtils: @capture
7676
@eqtest f(b^b) == b
7777
@test f(b+b) == nothing
7878
end
79+
80+
@testset "Rewriter tweaks #548" begin
81+
struct MetaData end
82+
ex = a + b
83+
ex = setmetadata(ex, MetaData, :metadata)
84+
ex1 = ex + c
85+
86+
@test SymbolicUtils.isterm(ex1)
87+
@test getmetadata(arguments(ex1)[1], MetaData) == :metadata
88+
89+
ex = a
90+
ex = setmetadata(ex, MetaData, :metadata)
91+
ex1 = ex + b
92+
93+
@test getmetadata(arguments(ex1)[1], MetaData) == :metadata
94+
end

0 commit comments

Comments
 (0)