diff --git a/src/chisels.jl b/src/chisels.jl index ee2ac95..b556e71 100644 --- a/src/chisels.jl +++ b/src/chisels.jl @@ -490,7 +490,7 @@ function has_newline_after_non_whitespace(node::Node) kids = verified_kids(node) idx = findlast(!JuliaSyntax.is_whitespace, kids) if idx === nothing - @assert false + unreachable() # Everything is whitespace... return any(x -> kind(x) === K"NewlineWs", kids) end diff --git a/src/debug.jl b/src/debug.jl index d9f4644..77400ea 100644 --- a/src/debug.jl +++ b/src/debug.jl @@ -16,7 +16,7 @@ end function Base.showerror(io::IO, err::AssertionError) print( io, - "Runic.AssertionError: `", err.msg, "`. This is unexpected, " * + "Runic.AssertionError: ", err.msg, ". This is unexpected, " * "please file an issue with a reproducible example at " * "https://github.com/fredrikekre/Runic.jl/issues/new." ) @@ -27,3 +27,5 @@ function macroexpand_assert(expr) msg = string(expr) return :($(esc(expr)) || throw(AssertionError($msg))) end + +@noinline unreachable() = throw(AssertionError("unreachable code reached")) diff --git a/src/runestone.jl b/src/runestone.jl index 16bb83e..20e1aaf 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -543,7 +543,7 @@ function spaces_in_listlike(ctx::Context, node::Node) accept_node!(ctx, kid′) any_kid_changed && push!(kids′, kid′) else - @assert false # Unreachable? + unreachable() end # Transition to the next state state = before_last_item ? (:expect_space) : (:expect_closing) @@ -660,7 +660,7 @@ function spaces_in_listlike(ctx::Context, node::Node) # K"parameters"... state = i == last_item_idx ? (:expect_closing) : (:expect_item) else - @assert false # Unreachable? + unreachable() end elseif state === :expect_space if (kind(kid′) === K"Whitespace" && span(kid′) == 1) || @@ -759,7 +759,7 @@ function spaces_in_listlike(ctx::Context, node::Node) accept_node!(ctx, kid′) any_kid_changed && push!(kids′, kid′) else - @assert false # Unreachable? + unreachable() end end # if-state any_kid_changed |= this_kid_changed @@ -780,7 +780,7 @@ function spaces_in_listlike(ctx::Context, node::Node) accept_node!(ctx, comma) state = :expect_closing else - @assert false # Unreachable? + unreachable() end end @assert state === :expect_closing @@ -896,7 +896,7 @@ function no_spaces_around_x(ctx::Context, node::Node, is_x::F) where {F} # Remove trailing whitespace ws_kid = last_leaf(kid) if kind(ws_kid) === K"Whitespace" - @assert false # Hope this doesn't happen often... + unreachable() end end end @@ -994,7 +994,7 @@ function spaces_in_export_public(ctx::Context, node::Node) accept_node!(ctx, kid) state = :expect_space else - @assert false + unreachable() end else @assert state === :expect_comma @@ -1011,7 +1011,7 @@ function spaces_in_export_public(ctx::Context, node::Node) end state = :expect_comma else - @assert false + unreachable() end end i += 1 @@ -1331,7 +1331,7 @@ function spaces_around_keywords(ctx::Context, node::Node) push!(kids′, kid′) end elseif !space_after && kind(last_leaf(kid)) === K"Whitespace" - @assert false # Unreachable? + unreachable() else # Reachable in e.g. `T where{T}`, `if(`, ... insert space @assert kind(node) in KSet"where if elseif while do function return local global module baremodule"