Explicitly handle all enum values in more switch statements

This addresses a few places where -Wswitch-enum showed one or two missing
case's for enum values.

It did uncover and fix one apparent oversight:

$ function asd -p 100
   echo foo
end

$ functions --handlers-type exit
Event exit
asd

It looks like this should be showing a PID before 'asd' just like
job_exit handlers show the job id. It was falling
through to default: which just printed the function name.

$ functions --handlers-type exit
Event exit
100 asd
This commit is contained in:
Aaron Gyes 2019-03-11 14:53:26 -07:00
parent 3e8c05e32b
commit 2ae6e5a585
5 changed files with 27 additions and 6 deletions

View File

@ -176,6 +176,7 @@ static wcstring functions_def(const wcstring &name) {
append_format(out, L" --on-event %ls", d.str_param1.c_str());
break;
}
case event_type_t::any:
default: {
DIE("unexpected next->type");
break;

View File

@ -131,9 +131,9 @@ static const wchar_t *math_get_arg(int *argidx, wchar_t **argv, wcstring *storag
static wcstring math_describe_error(te_error_t& error) {
if (error.position == 0) return L"NO ERROR?!?";
assert(error.type != TE_ERROR_NONE && L"Error has no position");
switch(error.type) {
case TE_ERROR_NONE: DIE("Error has no position");
case TE_ERROR_UNKNOWN_VARIABLE: return _(L"Unknown variable");
case TE_ERROR_MISSING_CLOSING_PAREN: return _(L"Missing closing parenthesis");
case TE_ERROR_MISSING_OPENING_PAREN: return _(L"Missing opening parenthesis");

View File

@ -429,7 +429,15 @@ static inline bool match_type_requires_full_replacement(fuzzy_match_type_t t) {
case fuzzy_match_prefix: {
return false;
}
default: { return true; }
case fuzzy_match_case_insensitive:
case fuzzy_match_prefix_case_insensitive:
case fuzzy_match_substring:
case fuzzy_match_substring_case_insensitive:
case fuzzy_match_subsequence_insertions_only:
case fuzzy_match_none:
{
return true;
}
}
}
@ -442,7 +450,12 @@ static inline bool match_type_shares_prefix(fuzzy_match_type_t t) {
case fuzzy_match_prefix_case_insensitive: {
return true;
}
default: { return false; }
case fuzzy_match_substring:
case fuzzy_match_substring_case_insensitive:
case fuzzy_match_subsequence_insertions_only:
case fuzzy_match_none: {
return false;
}
}
}

View File

@ -120,7 +120,8 @@ static bool handler_matches(const event_handler_t &classv, const event_t &instan
case event_type_t::generic: {
return classv.desc.str_param1 == instance.desc.str_param1;
}
default: {
case event_type_t::any: {
default:
DIE("unexpected classv.type");
return false;
}
@ -165,7 +166,7 @@ wcstring event_get_desc(const event_t &evt) {
-ed.param1.pid);
}
}
assert(0 && "Unreachable");
DIE("Unreachable");
}
case event_type_t::job_exit: {
@ -182,6 +183,7 @@ wcstring event_get_desc(const event_t &evt) {
case event_type_t::generic: {
return format_string(_(L"handler for generic event '%ls'"), ed.str_param1.c_str());
}
case event_type_t::any: { DIE("Unreachable"); }
default:
DIE("Unknown event type");
}
@ -409,6 +411,7 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
streams.out.append_format(L"%ls %ls\n", sig2wcs(evt->desc.param1.signal),
evt->function_name.c_str());
break;
case event_type_t::exit:
case event_type_t::job_exit:
streams.out.append_format(L"%d %ls\n", evt->desc.param1,
evt->function_name.c_str());
@ -418,6 +421,7 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
streams.out.append_format(L"%ls %ls\n", evt->desc.str_param1.c_str(),
evt->function_name.c_str());
break;
case event_type_t::any: DIE("Unreachable");
default:
streams.out.append_format(L"%ls\n", evt->function_name.c_str());
break;

View File

@ -408,7 +408,10 @@ int oflags_for_redirection_type(redirection_type_t type) {
case redirection_type_t::input: {
return O_RDONLY;
}
default: { return -1; }
case redirection_type_t::fd:
default: {
return -1;
}
}
}