diff options
| author | gingerBill <bill@gingerbill.org> | 2020-05-13 23:33:03 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-05-13 23:33:03 +0100 |
| commit | d59fced21b0c94a4a41f0213f62120dbe0f9b710 (patch) | |
| tree | ffbabc4413fa28104b33ecc4a93d5b202b5558fc /src/check_stmt.cpp | |
| parent | 7c42d4ba75b0d063ae6d9ebb704068f3ebe16847 (diff) | |
#591 Improve type switch statement error for `fallthrough`
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 3e84db279..92155cc5e 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1025,7 +1025,7 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(ss, TypeSwitchStmt, node); Operand x = {}; - mod_flags |= Stmt_BreakAllowed; + mod_flags |= Stmt_BreakAllowed | Stmt_TypeSwitch; check_open_scope(ctx, node); defer (check_close_scope(ctx)); @@ -1791,7 +1791,11 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { break; case Token_fallthrough: if ((flags & Stmt_FallthroughAllowed) == 0) { - error(token, "'fallthrough' statement in illegal position, expected at the end of a 'case' block"); + if ((flags & Stmt_TypeSwitch) != 0) { + error(token, "'fallthrough' statement not allowed within a type switch statement"); + } else { + error(token, "'fallthrough' statement in illegal position, expected at the end of a 'case' block"); + } } else if (bs->label != nullptr) { error(token, "'fallthrough' cannot have a label"); } |