Skip to content

Commit

Permalink
Clean up some asserts (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Nov 6, 2024
1 parent c9d74ea commit 6bd8eae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/chisels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand All @@ -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 changes: 8 additions & 9 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

2 comments on commit 6bd8eae

@fredrikekre
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/117521

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" 6bd8eaebed5b19859cd6b2771c05c053ad482384
git push origin v1.0.0

Please sign in to comment.