Skip to content

Commit 2becf30

Browse files
committed
Use === for symbol comparisons
1 parent 70c908f commit 2becf30

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

src/diagnostics.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939

4040
first_byte(d::Diagnostic) = d.first_byte
4141
last_byte(d::Diagnostic) = d.last_byte
42-
is_error(d::Diagnostic) = d.level == :error
42+
is_error(d::Diagnostic) = d.level === :error
4343
Base.range(d::Diagnostic) = first_byte(d):last_byte(d)
4444

4545
# Make relative path into a file URL
@@ -54,9 +54,9 @@ function _file_url(filename)
5454
end
5555

5656
function show_diagnostic(io::IO, diagnostic::Diagnostic, source::SourceFile)
57-
color,prefix = diagnostic.level == :error ? (:light_red, "Error") :
58-
diagnostic.level == :warning ? (:light_yellow, "Warning") :
59-
diagnostic.level == :note ? (:light_blue, "Note") :
57+
color,prefix = diagnostic.level === :error ? (:light_red, "Error") :
58+
diagnostic.level === :warning ? (:light_yellow, "Warning") :
59+
diagnostic.level === :note ? (:light_blue, "Note") :
6060
(:normal, "Info")
6161
line, col = source_location(source, first_byte(diagnostic))
6262
linecol = "$line:$col"

src/expr.jl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
6969
headsym = !isnothing(headstr) ? Symbol(headstr) :
7070
error("Can't untokenize head of kind $(nodekind)")
7171
end
72-
if headsym == :string || headsym == :cmdstring
72+
if headsym === :string || headsym === :cmdstring
7373
# Julia string literals may be interspersed with trivia in two situations:
7474
# 1. Triple quoted string indentation is trivia
7575
# 2. An \ before newline removes the newline and any following indentation
@@ -93,7 +93,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
9393
end
9494
else
9595
e = _to_expr(node_args[i])
96-
if e isa String && headsym == :string
96+
if e isa String && headsym === :string
9797
# Wrap interpolated literal strings in (string) so we can
9898
# distinguish them from the surrounding text (issue #38501)
9999
# Ie, "$("str")" vs "str"
@@ -117,22 +117,22 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
117117
end
118118

119119
# Convert children
120-
insert_linenums = (headsym == :block || headsym == :toplevel) && need_linenodes
120+
insert_linenums = (headsym === :block || headsym === :toplevel) && need_linenodes
121121
args = Vector{Any}(undef, length(node_args)*(insert_linenums ? 2 : 1))
122-
if headsym == :for && length(node_args) == 2
122+
if headsym === :for && length(node_args) == 2
123123
# No line numbers in for loop iteration spec
124124
args[1] = _to_expr(node_args[1], iteration_spec=true, need_linenodes=false)
125125
args[2] = _to_expr(node_args[2])
126-
elseif headsym == :let && length(node_args) == 2
126+
elseif headsym === :let && length(node_args) == 2
127127
# No line numbers in let statement binding list
128128
args[1] = _to_expr(node_args[1], need_linenodes=false)
129129
args[2] = _to_expr(node_args[2])
130130
else
131131
eq_to_kw_in_call =
132-
((headsym == :call || headsym == :dotcall) && is_prefix_call(node)) ||
133-
headsym == :ref
134-
eq_to_kw_all = headsym == :parameters && !map_kw_in_params
135-
in_vcbr = headsym == :vect || headsym == :curly || headsym == :braces || headsym == :ref
132+
((headsym === :call || headsym === :dotcall) && is_prefix_call(node)) ||
133+
headsym === :ref
134+
eq_to_kw_all = headsym === :parameters && !map_kw_in_params
135+
in_vcbr = headsym === :vect || headsym === :curly || headsym === :braces || headsym === :ref
136136
if insert_linenums && isempty(node_args)
137137
push!(args, source_location(LineNumberNode, node.source, node.position))
138138
else
@@ -143,8 +143,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
143143
end
144144
eq_to_kw = eq_to_kw_in_call && i > 1 || eq_to_kw_all
145145
args[insert_linenums ? 2*i : i] =
146-
_to_expr(n, eq_to_kw=eq_to_kw,
147-
map_kw_in_params=in_vcbr)
146+
_to_expr(n, eq_to_kw=eq_to_kw, map_kw_in_params=in_vcbr)
148147
end
149148
if nodekind == K"block" && has_flags(node, PARENS_FLAG)
150149
popfirst!(args)
@@ -197,7 +196,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
197196
end
198197
elseif headsym === :where
199198
reorder_parameters!(args, 2)
200-
elseif headsym == :parens
199+
elseif headsym === :parens
201200
# parens are used for grouping and don't appear in the Expr AST
202201
return only(args)
203202
elseif headsym in (:try, :try_finally_catch)
@@ -245,15 +244,15 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
245244
pushfirst!(args, numeric_flags(flags(node)))
246245
elseif headsym === :typed_ncat
247246
insert!(args, 2, numeric_flags(flags(node)))
248-
# elseif headsym == :string && length(args) == 1 && version <= (1,5)
247+
# elseif headsym === :string && length(args) == 1 && version <= (1,5)
249248
# Strip string from interpolations in 1.5 and lower to preserve
250249
# "hi$("ho")" ==> (string "hi" "ho")
251250
elseif headsym === :(=) && !is_decorated(node)
252251
if is_eventually_call(args[1]) && !iteration_spec && !Meta.isexpr(args[2], :block)
253252
# Add block for short form function locations
254253
args[2] = Expr(:block, loc, args[2])
255254
end
256-
elseif headsym == :elseif
255+
elseif headsym === :elseif
257256
# Block for conditional's source location
258257
args[1] = Expr(:block, loc, args[1])
259258
elseif headsym === :(->)
@@ -283,7 +282,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
283282
elseif headsym === :module
284283
pushfirst!(args, !has_flags(node, BARE_MODULE_FLAG))
285284
pushfirst!(args[3].args, loc)
286-
elseif headsym == :inert || (headsym == :quote && length(args) == 1 &&
285+
elseif headsym === :inert || (headsym === :quote && length(args) == 1 &&
287286
!(a1 = only(args); a1 isa Expr || a1 isa QuoteNode ||
288287
a1 isa Bool # <- compat hack, Julia 1.4+
289288
))

src/hooks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ function _fl_parse_hook(code, filename, lineno, offset, options)
288288
ex = Expr(:toplevel, ex)
289289
end
290290
return ex, sizeof(code)
291-
elseif options === :statement || options == :atom
291+
elseif options === :statement || options === :atom
292292
ex, pos = Meta.parse(code, offset+1, greedy=options==:statement, raise=false)
293293
return ex, pos-1
294294
else

src/parse_stream.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,14 +890,14 @@ function validate_tokens(stream::ParseStream)
890890
# jl_strtod_c can return "underflow" even for valid cases such
891891
# as `5e-324` where the source is an exact representation of
892892
# `x`. So only warn when underflowing to zero.
893-
underflow0 = code == :underflow && x == 0
893+
underflow0 = code === :underflow && x == 0
894894
else
895895
x, code = parse_float_literal(Float32, text, fbyte, nbyte)
896-
underflow0 = code == :underflow && x == 0
896+
underflow0 = code === :underflow && x == 0
897897
end
898-
if code == :ok
898+
if code === :ok
899899
# pass
900-
elseif code == :overflow
900+
elseif code === :overflow
901901
emit_diagnostic(stream, fbyte, lbyte,
902902
error="overflow in floating point literal")
903903
error_kind = K"ErrorNumericOverflow"

src/syntax_tree.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ function SyntaxNode(source::SourceFile, raw::GreenNode{SyntaxHead}, position::In
6060
elseif k == K"Float"
6161
v, code = parse_float_literal(Float64, source.code, position,
6262
position+span(raw))
63-
(code == :ok || code == :underflow) ? v : ErrorVal()
63+
(code === :ok || code === :underflow) ? v : ErrorVal()
6464
elseif k == K"Float32"
6565
v, code = parse_float_literal(Float32, source.code, position,
6666
position+span(raw))
67-
(code == :ok || code == :underflow) ? v : ErrorVal()
67+
(code === :ok || code === :underflow) ? v : ErrorVal()
6868
elseif k in KSet"BinInt OctInt HexInt"
6969
parse_uint_literal(val_str, k)
7070
elseif k == K"true"

0 commit comments

Comments
 (0)