Skip to content

Commit f803fb0

Browse files
committed
Guard against the assumption children gives nodes
I've recently become aware that some dodgy syntax can result in numchildren(...) > 0 but no children(...), represented as nothing. We might as well systematically remove the chance of running into this. If this isn't the end of the syntax surprises, I'll look at what's needed to make JET confident there aren't any more lurking around the corner (this is probably a good idea anyway, but spinning plates and all that).
1 parent b7a1c63 commit f803fb0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/JuliaSyntaxHighlighting.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
215215
:julia_macro
216216
elseif nkind == K"StringMacroName"; :julia_macro
217217
elseif nkind == K"CmdMacroName"; :julia_macro
218-
elseif nkind == K"::";
218+
elseif nkind == K"::"
219219
if JuliaSyntax.is_trivia(node) || numchildren(node) == 0
220220
:julia_typedec
221221
else
222222
literal_typedecl = findfirst(
223-
c ->kind(c) == K"::" && JuliaSyntax.is_trivia(c),
224-
children(node))
223+
c -> kind(c) == K"::" && JuliaSyntax.is_trivia(c),
224+
something(children(node), GreenNode[]))
225225
if !isnothing(literal_typedecl)
226226
shift = sum(c ->Int(span(c)), node[1:literal_typedecl])
227227
region = first(region)+shift:last(region)
@@ -260,8 +260,8 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
260260
:julia_keyword
261261
else
262262
literal_where = findfirst(
263-
c ->kind(c) == K"where" && JuliaSyntax.is_trivia(c),
264-
children(node))
263+
c -> kind(c) == K"where" && JuliaSyntax.is_trivia(c),
264+
something(children(node), GreenNode[]))
265265
if !isnothing(literal_where)
266266
shift = sum(c ->Int(span(c)), node[1:literal_where])
267267
region = first(region)+shift:last(region)
@@ -281,7 +281,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
281281
:julia_broadcast
282282
elseif nkind in (K"call", K"dotcall") && JuliaSyntax.is_prefix_call(node)
283283
argoffset, arg1 = 0, nothing
284-
for arg in children(node)
284+
for arg in something(children(node), GreenNode[])
285285
argoffset += span(arg)
286286
if !JuliaSyntax.is_trivia(arg)
287287
arg1 = arg
@@ -338,7 +338,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
338338
end
339339
numchildren(node) == 0 && return
340340
lnode = node
341-
for child in children(node)
341+
for child in something(children(node), GreenNode[])
342342
cctx = HighlightContext(content, offset, lnode, pdepths)
343343
_hl_annotations!(highlights, GreenLineage(child, lineage), cctx)
344344
lnode = child

0 commit comments

Comments
 (0)