From 8d84206a8c6eeda626a719bbd3f4531d633921e2 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Wed, 10 Mar 2021 22:14:32 +0530 Subject: [PATCH] cgen: fix match for one branch (#9234) --- vlib/v/gen/c/cgen.v | 2 +- vlib/v/tests/match_expr_with_one_branch_test.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/match_expr_with_one_branch_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 831f71e912..abb7425dff 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -3810,7 +3810,7 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str } } g.stmts_with_tmp_var(branch.stmts, tmp_var) - if g.inside_ternary == 0 && node.branches.len > 1 { + if g.inside_ternary == 0 && node.branches.len >= 1 { g.write('}') } } diff --git a/vlib/v/tests/match_expr_with_one_branch_test.v b/vlib/v/tests/match_expr_with_one_branch_test.v new file mode 100644 index 0000000000..e38c13bb4d --- /dev/null +++ b/vlib/v/tests/match_expr_with_one_branch_test.v @@ -0,0 +1,12 @@ +enum Color { + red +} + +fn test_match_one_branch() { + col := Color.red + match col { + .red { + assert true + } + } +}