diff --git a/vlib/v/gen/c/match.v b/vlib/v/gen/c/match.v index bb87d58f28..ad5120fcd8 100644 --- a/vlib/v/gen/c/match.v +++ b/vlib/v/gen/c/match.v @@ -172,7 +172,11 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str be := unsafe { &branch.exprs[sumtype_index] } if sym.kind == .sum_type { g.write('${dot_or_ptr}_typ == ') - g.expr(be) + if be is ast.None { + g.write('$ast.none_type.idx() /* none */') + } else { + g.expr(be) + } } else if sym.kind == .interface_ { if be is ast.TypeNode { typ := be as ast.TypeNode diff --git a/vlib/v/tests/match_sumtype_var_with_none_test.v b/vlib/v/tests/match_sumtype_var_with_none_test.v new file mode 100644 index 0000000000..f3a90e3f47 --- /dev/null +++ b/vlib/v/tests/match_sumtype_var_with_none_test.v @@ -0,0 +1,13 @@ +fn number() int|none { + return none +} + +fn test_match_sumtype_var_with_none() { + n := number() + ret := match n { + int { 'n: $n' } + none { '?' } + } + println(ret) + assert ret == '?' +}