Browse Source

Clean up some asserts

pull/95/head
Fredrik Ekre 1 year ago
parent
commit
bf28ba495e
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  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)
kids = verified_kids(node) kids = verified_kids(node)
idx = findlast(!JuliaSyntax.is_whitespace, kids) idx = findlast(!JuliaSyntax.is_whitespace, kids)
if idx === nothing if idx === nothing
@assert false unreachable()
# Everything is whitespace... # Everything is whitespace...
return any(x -> kind(x) === K"NewlineWs", kids) return any(x -> kind(x) === K"NewlineWs", kids)
end end

4
src/debug.jl

@ -16,7 +16,7 @@ end
function Base.showerror(io::IO, err::AssertionError) function Base.showerror(io::IO, err::AssertionError)
print( print(
io, io,
"Runic.AssertionError: `", err.msg, "`. This is unexpected, " * "Runic.AssertionError: ", err.msg, ". This is unexpected, " *
"please file an issue with a reproducible example at " * "please file an issue with a reproducible example at " *
"https://github.com/fredrikekre/Runic.jl/issues/new." "https://github.com/fredrikekre/Runic.jl/issues/new."
) )
@ -27,3 +27,5 @@ function macroexpand_assert(expr)
msg = string(expr) msg = string(expr)
return :($(esc(expr)) || throw(AssertionError($msg))) return :($(esc(expr)) || throw(AssertionError($msg)))
end end
@noinline unreachable() = throw(AssertionError("unreachable code reached"))

17
src/runestone.jl

@ -543,7 +543,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
accept_node!(ctx, kid′) accept_node!(ctx, kid′)
any_kid_changed && push!(kids′, kid′) any_kid_changed && push!(kids′, kid′)
else else
@assert false # Unreachable? unreachable()
end end
# Transition to the next state # Transition to the next state
state = before_last_item ? (:expect_space) : (:expect_closing) state = before_last_item ? (:expect_space) : (:expect_closing)
@ -660,7 +660,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
# K"parameters"... # K"parameters"...
state = i == last_item_idx ? (:expect_closing) : (:expect_item) state = i == last_item_idx ? (:expect_closing) : (:expect_item)
else else
@assert false # Unreachable? unreachable()
end end
elseif state === :expect_space elseif state === :expect_space
if (kind(kid′) === K"Whitespace" && span(kid′) == 1) || if (kind(kid′) === K"Whitespace" && span(kid′) == 1) ||
@ -759,7 +759,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
accept_node!(ctx, kid′) accept_node!(ctx, kid′)
any_kid_changed && push!(kids′, kid′) any_kid_changed && push!(kids′, kid′)
else else
@assert false # Unreachable? unreachable()
end end
end # if-state end # if-state
any_kid_changed |= this_kid_changed any_kid_changed |= this_kid_changed
@ -780,7 +780,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
accept_node!(ctx, comma) accept_node!(ctx, comma)
state = :expect_closing state = :expect_closing
else else
@assert false # Unreachable? unreachable()
end end
end end
@assert state === :expect_closing @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 # Remove trailing whitespace
ws_kid = last_leaf(kid) ws_kid = last_leaf(kid)
if kind(ws_kid) === K"Whitespace" if kind(ws_kid) === K"Whitespace"
@assert false # Hope this doesn't happen often... unreachable()
end end
end end
end end
@ -994,7 +994,7 @@ function spaces_in_export_public(ctx::Context, node::Node)
accept_node!(ctx, kid) accept_node!(ctx, kid)
state = :expect_space state = :expect_space
else else
@assert false unreachable()
end end
else else
@assert state === :expect_comma @assert state === :expect_comma
@ -1011,7 +1011,7 @@ function spaces_in_export_public(ctx::Context, node::Node)
end end
state = :expect_comma state = :expect_comma
else else
@assert false unreachable()
end end
end end
i += 1 i += 1
@ -1331,7 +1331,7 @@ function spaces_around_keywords(ctx::Context, node::Node)
push!(kids′, kid′) push!(kids′, kid′)
end end
elseif !space_after && kind(last_leaf(kid)) === K"Whitespace" elseif !space_after && kind(last_leaf(kid)) === K"Whitespace"
@assert false # Unreachable? unreachable()
else else
# Reachable in e.g. `T where{T}`, `if(`, ... insert space # 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" @assert kind(node) in KSet"where if elseif while do function return local global module baremodule"
@ -2514,7 +2514,6 @@ function indent_listlike(
push!(kids′, kid) push!(kids′, kid)
accept_node!(ctx, kid) accept_node!(ctx, kid)
elseif kind(last_leaf(kid)) === K"NewlineWs" elseif kind(last_leaf(kid)) === K"NewlineWs"
# @assert false # Testcase?
# Hidden newline without tag # Hidden newline without tag
grandkid = last_leaf(kid) grandkid = last_leaf(kid)
@assert !has_tag(grandkid, TAG_PRE_DEDENT) @assert !has_tag(grandkid, TAG_PRE_DEDENT)

Loading…
Cancel
Save