Skip to content

Commit 0a25eac

Browse files
Merge pull request #651 from JuliaSymbolics/occursin
Fix occursin for needle as a number case
2 parents b959fd8 + 570b0d0 commit 0a25eac

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/substitute.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ Base.occursin(needle, haystack::Symbolic) = _occursin(needle, haystack)
5151
Base.occursin(needle::Symbolic, haystack) = _occursin(needle, haystack)
5252
function _occursin(needle, haystack)
5353
isequal(needle, haystack) && return true
54-
5554
if iscall(haystack)
5655
args = arguments(haystack)
5756
for arg in args
58-
occursin(needle, arg) && return true
57+
if needle isa Integer || needle isa AbstractFloat
58+
isequal(needle, arg) && return true
59+
else
60+
occursin(needle, arg) && return true
61+
end
5962
end
6063
end
6164
return false

test/basics.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ end
184184
@test occursin(a, a + b)
185185
@test !occursin(sin(a), a + b + c)
186186
@test occursin(sin(a), a * b + c + sin(a^2 * sin(a)))
187+
@test occursin(0.01, 0.01*a)
188+
@test !occursin(0.01, a * b * c)
187189
end
188190

189191
@testset "printing" begin

0 commit comments

Comments
 (0)