Browse Source

Clean up some asserts (#95)

pull/99/head v1.0.0
Fredrik Ekre 1 year ago committed by GitHub
parent
commit
6bd8eaebed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      src/chisels.jl
  2. 4
      src/debug.jl
  3. 17
      src/runestone.jl

2
src/chisels.jl

@ -490,7 +490,7 @@ function has_newline_after_non_whitespace(node::Node) @@ -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

4
src/debug.jl

@ -16,7 +16,7 @@ end @@ -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) @@ -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"))

17
src/runestone.jl

@ -543,7 +543,7 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -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) @@ -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) @@ -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) @@ -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} @@ -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) @@ -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) @@ -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) @@ -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"
@ -2514,7 +2514,6 @@ function indent_listlike( @@ -2514,7 +2514,6 @@ function indent_listlike(
push!(kids′, kid)
accept_node!(ctx, kid)
elseif kind(last_leaf(kid)) === K"NewlineWs"
# @assert false # Testcase?
# Hidden newline without tag
grandkid = last_leaf(kid)
@assert !has_tag(grandkid, TAG_PRE_DEDENT)

Loading…
Cancel
Save