mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix match sumtyp var with none (#15495)
This commit is contained in:
parent
8db945ec52
commit
18b6311b2f
@ -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] }
|
be := unsafe { &branch.exprs[sumtype_index] }
|
||||||
if sym.kind == .sum_type {
|
if sym.kind == .sum_type {
|
||||||
g.write('${dot_or_ptr}_typ == ')
|
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_ {
|
} else if sym.kind == .interface_ {
|
||||||
if be is ast.TypeNode {
|
if be is ast.TypeNode {
|
||||||
typ := be as ast.TypeNode
|
typ := be as ast.TypeNode
|
||||||
|
13
vlib/v/tests/match_sumtype_var_with_none_test.v
Normal file
13
vlib/v/tests/match_sumtype_var_with_none_test.v
Normal file
@ -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 == '?'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user