From c9e2b6c29432748df1acde6a24e3cc8b00ea6eaa Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 23 Aug 2024 01:08:59 +0200 Subject: [PATCH] Fix a bug in do-block tree normalization --- src/chisels.jl | 4 +++- test/runtests.jl | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/chisels.jl b/src/chisels.jl index bdc5383..1d3b586 100644 --- a/src/chisels.jl +++ b/src/chisels.jl @@ -154,7 +154,9 @@ function normalize_tree!(node) # If the tuple ends with a K"NewlineWs" node we move it into the block block = kids[blockidx] blockkids = verified_kids(block) - @assert kind(blockkids[1]) !== K"Whitespace" + if length(blockkids) > 0 + @assert kind(blockkids[1]) !== K"Whitespace" + end pushfirst!(blockkids, pop!(tuplekids)) # Remake the nodes to recompute the spans kids[tupleidx] = make_node(tuple, tuplekids) diff --git a/test/runtests.jl b/test/runtests.jl index 3ac2cd4..01c454e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1033,6 +1033,7 @@ end end # do-end @test format_string("open() do\na$(d)end") == "open() do\n a\nend" + @test format_string("open() do\nend") == "open() do\nend" @test_broken format_string("open() do;a$(d)end") == "open() do\n a\nend" @test_broken format_string("open() do ;a$(d)end") == "open() do\n a\nend" @test format_string("open() do io$(d)a end") == "open() do io\n a\nend"