Skip to content

Commit 65c5553

Browse files
authored
Merge pull request #168 from aviatesk/avi/inf
use `===` and `!==` in more places to improve inferrabilities
2 parents 7bc92b7 + bdf210b commit 65c5553

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MacroTools"
22
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
3-
version = "0.5.7"
3+
version = "0.5.8"
44

55
[deps]
66
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"

src/match/macro.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function allbindings(pat, bs)
22
if isa(pat, QuoteNode)
33
return allbindings(pat.value, bs)
44
end
5-
return isbinding(pat) || (isslurp(pat) && pat :__) ? push!(bs, bname(pat)) :
5+
return isbinding(pat) || (isslurp(pat) && pat !== :__) ? push!(bs, bname(pat)) :
66
isa(pat, TypeBind) ? push!(bs, pat.name) :
77
isa(pat, OrBind) ? (allbindings(pat.pat1, bs); allbindings(pat.pat2, bs)) :
88
istb(pat) ? push!(bs, tbname(pat)) :
@@ -25,7 +25,7 @@ function makeclause(pat, yes, els = nothing)
2525
pat = subtb(subor(pat))
2626
quote
2727
env = trymatch($(Expr(:quote, pat)), ex)
28-
if env != nothing
28+
if env !== nothing
2929
$(bindinglet(bs, esc(yes)))
3030
else
3131
$els

src/match/match.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ match_inner(pat::QuoteNode, ex::QuoteNode, env) =
3636
match(pat.value, ex.value, env)
3737

3838
isslurp(s) = false
39-
isslurp(s::Symbol) = s == :__ || occursin(r"[^_]__$", string(s))
39+
isslurp(s::Symbol) = s === :__ || occursin(r"[^_]__$", string(s))
4040

4141
function slurprange(pat)
4242
slurps = length(filter(isslurp, pat))
@@ -68,7 +68,7 @@ function match_inner(pat::Expr, ex::Expr, env)
6868
end
6969

7070
if isslurp(p)
71-
p :__ && @trymatch store!(env, bname(p), slurp)
71+
p !== :__ && @trymatch store!(env, bname(p), slurp)
7272
else
7373
@trymatch match(p, ex.args[i], env)
7474
i += 1
@@ -101,7 +101,7 @@ function match(pat, ex, env)
101101
ex = normalise(ex)
102102
pat, ex = blockunify(pat, ex)
103103
isslurp(pat) && return store!(env, bname(pat), Any[ex])
104-
return match_inner(pat, ex, env)
104+
return match_inner(pat, ex, env)::Union{typeof(env),MatchError,Nothing}
105105
end
106106

107107
match(pat, ex) = match(pat, ex, Dict())

src/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ rmlines(x) = x
7777
function rmlines(x::Expr)
7878
# Do not strip the first argument to a macrocall, which is
7979
# required.
80-
if x.head == :macrocall && length(x.args) >= 2
80+
if x.head === :macrocall && length(x.args) >= 2
8181
Expr(x.head, x.args[1], nothing, filter(x->!isline(x), x.args[3:end])...)
8282
else
8383
Expr(x.head, filter(x->!isline(x), x.args)...)
@@ -161,9 +161,9 @@ isgensym(s) = false
161161

162162
function gensymname(x::Symbol)
163163
m = Base.match(r"##(.+)#\d+", String(x))
164-
m == nothing || return m.captures[1]
164+
m === nothing || return m.captures[1]
165165
m = Base.match(r"#\d+#(.+)", String(x))
166-
m == nothing || return m.captures[1]
166+
m === nothing || return m.captures[1]
167167
return "x"
168168
end
169169

0 commit comments

Comments
 (0)