Skip to content

Commit

Permalink
Clean up some asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Nov 6, 2024
1 parent c9d74ea commit a48b724
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 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()

Check warning on line 493 in src/chisels.jl

View check run for this annotation

Codecov / codecov/patch

src/chisels.jl#L493

Added line #L493 was not covered by tests
# 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"))

Check warning on line 31 in src/debug.jl

View check run for this annotation

Codecov / codecov/patch

src/debug.jl#L31

Added line #L31 was not covered by tests
16 changes: 8 additions & 8 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()

Check warning on line 546 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L546

Added line #L546 was not covered by tests
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()

Check warning on line 663 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L663

Added line #L663 was not covered by tests
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()

Check warning on line 762 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L762

Added line #L762 was not covered by tests
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()

Check warning on line 783 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L783

Added line #L783 was not covered by tests
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()

Check warning on line 899 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L899

Added line #L899 was not covered by tests
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()

Check warning on line 997 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L997

Added line #L997 was not covered by tests
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()

Check warning on line 1014 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L1014

Added line #L1014 was not covered by tests
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()

Check warning on line 1334 in src/runestone.jl

View check run for this annotation

Codecov / codecov/patch

src/runestone.jl#L1334

Added line #L1334 was not covered by tests
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

0 comments on commit a48b724

Please sign in to comment.