1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix match comparing with ident of type string (#7921)

This commit is contained in:
Daniel Däschle 2021-01-06 19:03:50 +01:00 committed by GitHub
parent dcc8310bd0
commit a8e4d1df40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -3393,7 +3393,7 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
g.write(' || ') g.write(' || ')
} }
if type_sym.kind == .string { 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') g.write('${cond_var}.len == 0')
} else { } else {
g.write('string_eq(') g.write('string_eq(')

View File

@ -230,3 +230,18 @@ fn test_sub_expression() {
c := true || match 1 {0 {false} else {false}} c := true || match 1 {0 {false} else {false}}
assert c assert c
} }
const (
one = 'one'
)
fn test_match_constant_string() {
match one {
one {
assert true
}
else {
assert false
}
}
}