diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index f14c799a6c..8791a8bb31 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3393,7 +3393,7 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str g.write(' || ') } if type_sym.kind == .string { - if (expr as ast.StringLiteral).val == '' { + if expr is ast.StringLiteral && (expr as ast.StringLiteral).val == '' { g.write('${cond_var}.len == 0') } else { g.write('string_eq(') diff --git a/vlib/v/tests/match_test.v b/vlib/v/tests/match_test.v index 2bd44ea6c9..9f829d3d69 100644 --- a/vlib/v/tests/match_test.v +++ b/vlib/v/tests/match_test.v @@ -230,3 +230,18 @@ fn test_sub_expression() { c := true || match 1 {0 {false} else {false}} assert c } + +const ( + one = 'one' +) + +fn test_match_constant_string() { + match one { + one { + assert true + } + else { + assert false + } + } +}