aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/option.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2023-10-09 00:36:48 +0600
committerLewis Russell <me@lewisr.dev>2023-10-10 11:19:41 +0100
commit9ff6f73f838a1f90d09922448c434033ba5e094e (patch)
tree5368bcb5ddee303c299863fb59d7671d2958a342 /src/nvim/option.c
parenta2f17e97ec2d3767a978889320c1a9fb3d82d5b0 (diff)
downloadrneovim-9ff6f73f838a1f90d09922448c434033ba5e094e.tar.gz
rneovim-9ff6f73f838a1f90d09922448c434033ba5e094e.tar.bz2
rneovim-9ff6f73f838a1f90d09922448c434033ba5e094e.zip
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.
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r--src/nvim/option.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 0700d0e87e..6a3079e0a6 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -3461,9 +3461,8 @@ OptVal optval_copy(OptVal o)
return o;
case kOptValTypeString:
return STRING_OPTVAL(copy_string(o.data.string, NULL));
- default:
- abort();
}
+ UNREACHABLE;
}
// Match type of OptVal with the type of the target option. Returns true if the types match and
@@ -3482,9 +3481,8 @@ static bool optval_match_type(OptVal o, int opt_idx)
return flags & P_NUM;
case kOptValTypeString:
return flags & P_STRING;
- default:
- abort();
}
+ UNREACHABLE;
}
// Return C-string representation of OptVal. Caller must free the returned C-string.
@@ -3505,9 +3503,8 @@ static char *optval_to_cstr(OptVal o)
snprintf(buf, o.data.string.size + 3, "\"%s\"", o.data.string.data);
return buf;
}
- default:
- abort();
}
+ UNREACHABLE;
}
// Get an allocated string containing a list of valid types for an option.