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:
parent
dcc8310bd0
commit
a8e4d1df40
@ -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(')
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user