mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
#591 Improve type switch statement error for fallthrough
This commit is contained in:
+6
-2
@@ -1025,7 +1025,7 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
|||||||
ast_node(ss, TypeSwitchStmt, node);
|
ast_node(ss, TypeSwitchStmt, node);
|
||||||
Operand x = {};
|
Operand x = {};
|
||||||
|
|
||||||
mod_flags |= Stmt_BreakAllowed;
|
mod_flags |= Stmt_BreakAllowed | Stmt_TypeSwitch;
|
||||||
check_open_scope(ctx, node);
|
check_open_scope(ctx, node);
|
||||||
defer (check_close_scope(ctx));
|
defer (check_close_scope(ctx));
|
||||||
|
|
||||||
@@ -1791,7 +1791,11 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
|||||||
break;
|
break;
|
||||||
case Token_fallthrough:
|
case Token_fallthrough:
|
||||||
if ((flags & Stmt_FallthroughAllowed) == 0) {
|
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) {
|
} else if (bs->label != nullptr) {
|
||||||
error(token, "'fallthrough' cannot have a label");
|
error(token, "'fallthrough' cannot have a label");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ enum StmtFlag {
|
|||||||
Stmt_ContinueAllowed = 1<<1,
|
Stmt_ContinueAllowed = 1<<1,
|
||||||
Stmt_FallthroughAllowed = 1<<2,
|
Stmt_FallthroughAllowed = 1<<2,
|
||||||
|
|
||||||
|
Stmt_TypeSwitch = 1<<4,
|
||||||
|
|
||||||
Stmt_CheckScopeDecls = 1<<5,
|
Stmt_CheckScopeDecls = 1<<5,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user