Skip to content

Commit

Permalink
Allow fallthrough on empty cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan authored and well-in-that-case committed May 14, 2024
1 parent 2ed87ce commit 60e6a39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3310,7 +3310,14 @@ static void switchimpl (LexState *ls, int tk, void(*caselist)(LexState*,void*),
static void switchstat (LexState *ls) {
switchimpl(ls, ':', [](LexState* ls, void*) {
const int case_line = luaX_lookbehind(ls).line;
if (gett(ls) != TK_CASE && gett(ls) != TK_DEFAULT && gett(ls) != TK_END && gett(ls) != TK_FALLTHROUGH) { /* non-empty case? */
if (gett(ls) == TK_CASE || gett(ls) == TK_DEFAULT || gett(ls) == TK_END) {
/* this case is empty, nothing to do */
}
else if (gett(ls) == TK_FALLTHROUGH) {
/* empty case explicitly declaring itself to be a fallthrough */
luaX_next(ls);
}
else {
do {
statement(ls);
}
Expand Down
6 changes: 6 additions & 0 deletions testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,12 @@ switch 1 do
print("OK")
end
]] == nil)
-- Fallthrough can be used on empty cases
switch 1 do
case 1:
--[[@fallthrough]]
case 2:
end

print "Testing switch expression."
do
Expand Down

0 comments on commit 60e6a39

Please sign in to comment.