From 9ff6f73f838a1f90d09922448c434033ba5e094e Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 9 Oct 2023 00:36:48 +0600 Subject: refactor: allow not having a `default` case for enum Problem: The style guide states that all switch statements that are not conditional on an enum must have a `default` case, but does not give any explicit guideline for switch statements that are conditional on enums. As a result, a `default` case is added in many enum switch statements, even when the switch statement is exhaustive. This is not ideal because it removes the ability to have compiler errors to easily detect unchanged switch statements when a new possible value for an enum is added. Solution: Add explicit guidelines for switch statements that are conditional on an enum, clarifying that a `default` case is not necessary if the switch statement is exhaustive. Also refactor pre-existing code with unnecessary `default` cases. --- src/nvim/api/options.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/options.c') diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 5a75d10043..867d1d5e5c 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -146,16 +146,14 @@ static Object optval_as_object(OptVal o) return BOOLEAN_OBJ(o.data.boolean); case kNone: return NIL; - default: - abort(); } + UNREACHABLE; case kOptValTypeNumber: return INTEGER_OBJ(o.data.number); case kOptValTypeString: return STRING_OBJ(o.data.string); - default: - abort(); } + UNREACHABLE; } /// Consume an API Object and convert it to an OptVal. -- cgit