From 41e0e31b8586c1f93b5e65cd62ef910227a6677d Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 24 May 2025 14:18:51 +0200 Subject: Failure when default case reached in non-optional switch functions Signed-off-by: Mel --- boot/lex.c | 3 ++- boot/tree.c | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'boot') diff --git a/boot/lex.c b/boot/lex.c index 0fc6ed1..c66d160 100644 --- a/boot/lex.c +++ b/boot/lex.c @@ -275,7 +275,8 @@ token_kind_to_string(enum Token_Kind kind) return "ASSIGN_RIGHT_SHIFT"; default: - return ""; + failure("unknown token kind passed to `token_kind_to_string`"); + return nil; } } diff --git a/boot/tree.c b/boot/tree.c index e6c5b78..593103a 100644 --- a/boot/tree.c +++ b/boot/tree.c @@ -40,7 +40,8 @@ unary_operation_to_string(enum Unary_Operation operation) return "~"; default: - return "unknown"; + failure("unexpected unary operation passed to `unary_operation_to_string`"); + return nil; } } @@ -212,6 +213,7 @@ binary_operation_precedence(enum Binary_Operation operation) // strongest default: + failure("unexpected binary operation passed to `binary_operation_precedence`"); return 0; } } @@ -316,7 +318,8 @@ binary_operation_to_string(enum Binary_Operation operation) return ">>="; default: - return "unknown"; + failure("unexpected binary operation passed to `binary_operation_to_string`"); + return nil; } } @@ -511,6 +514,7 @@ expression_print(const struct Expression* expression) printf(")"); break; default: + failure("unexpected expression kind passed to `expression_print`"); break; } printf(")"); @@ -572,7 +576,7 @@ statement_print(const struct Statement* statement) break; } default: - printf("unknown"); + failure("unexpected statement kind passed to `statement_print`"); break; } printf(")"); -- cgit 1.4.1