From c05634ebd138588d4b67e25d6eb740ce927a7739 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 19 Mar 2022 21:43:42 +0200 Subject: [PATCH] ci: fix sanitize job failures after 02b889d --- vlib/v/gen/c/match.v | 6 ++++++ vlib/v/gen/c/testdata/enum_switch_case.c.must_have | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/match.v b/vlib/v/gen/c/match.v index 2852d87d16..bb07b2ce4e 100644 --- a/vlib/v/gen/c/match.v +++ b/vlib/v/gen/c/match.v @@ -183,6 +183,7 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str } fn (mut g Gen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var string, tmp_var string, enum_typ ast.TypeSymbol) { + cname := '${enum_typ.cname}__' mut covered_enum := []string{cap: (enum_typ.info as ast.Enum).vals.len} // collects missing enum variant branches to avoid cstrict errors mut range_branches := []ast.MatchBranch{cap: node.branches.len} // branches have RangeExpr cannot emit as switch case branch, we handle it in default branch mut default_generated := false @@ -191,6 +192,11 @@ fn (mut g Gen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var stri g.indent++ for branch in node.branches { if branch.is_else { + for val in (enum_typ.info as ast.Enum).vals { + if val !in covered_enum { + g.writeln('case $cname$val:') + } + } g.writeln('default:') default_generated = true if range_branches.len > 0 { diff --git a/vlib/v/gen/c/testdata/enum_switch_case.c.must_have b/vlib/v/gen/c/testdata/enum_switch_case.c.must_have index c0b9ff794b..c9d9cec28b 100644 --- a/vlib/v/gen/c/testdata/enum_switch_case.c.must_have +++ b/vlib/v/gen/c/testdata/enum_switch_case.c.must_have @@ -1,4 +1,5 @@ case main__Enum__e1: case main__Enum__e4: +case main__Enum__e6: default: -(e >= 4 && e <= 5) +(e >= 4 && e <= 5) \ No newline at end of file