Skip to content

Commit 4ee4ebb

Browse files
committed
fixed predicates with defslots
1 parent ea651d5 commit 4ee4ebb

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/matchers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function term_matcher_constructor(term, acSets)
184184

185185
for inds in acSets(eachindex(data_args), length(data_args))
186186
candidate = Term{T}(f, @views data_args[inds])
187-
187+
188188
result = loop(candidate, bindings, matchers)
189189
result !== nothing && return success(result,1)
190190
end

src/rule.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function makeDefSlot(s::Expr, keys, op)
8282

8383
push!(keys, name)
8484
tmp = defaultValOfCall(op)
85-
:(DefSlot($(QuoteNode(name)), $(esc(s.args[2])), $(esc(op))), $(esc(tmp)))
85+
:(DefSlot($(QuoteNode(name)), $(esc(s.args[2])), $(esc(op)), $(esc(tmp))))
8686
end
8787

8888

test/rewrite.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ end
108108
@test r_mixmix(exp(x)*sin(1+x+x^2)*2) === (2, 1, x)
109109
@test r_mixmix(exp(x)*sin(x+x^2)*2) === (2, 0, x)
110110
@test r_mixmix(exp(x)*sin(x+x^2)) === (1, 0, x)
111+
112+
r_predicate = @rule ~x + (~!m::(var->isa(var, Int))) => (~x, ~m)
113+
@test r_predicate(x+2) === (x, 2)
114+
@test r_predicate(x+2.0) !== (x, 2.0)
115+
# Note: r_predicate(x+2.0) doesnt return nothing, but (x+2.0, 0)
116+
# becasue of the defslot
111117
end
112118

113119
@testset "power matcher with negative exponent" begin

0 commit comments

Comments
 (0)