checker: fix if expr with enum value (#13685)
parent
f6aba9a3fe
commit
3fe8204062
|
@ -21,6 +21,12 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
|||
}
|
||||
expr_required := c.expected_type != ast.void_type
|
||||
former_expected_type := c.expected_type
|
||||
if node_is_expr {
|
||||
c.expected_expr_type = c.expected_type
|
||||
defer {
|
||||
c.expected_expr_type = ast.void_type
|
||||
}
|
||||
}
|
||||
node.typ = ast.void_type
|
||||
mut nbranches_with_return := 0
|
||||
mut nbranches_without_return := 0
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
enum Foo {
|
||||
a
|
||||
b
|
||||
}
|
||||
|
||||
fn get() Foo {
|
||||
return .a
|
||||
}
|
||||
|
||||
fn foo(f Foo) string {
|
||||
println(f)
|
||||
return '$f'
|
||||
}
|
||||
|
||||
fn test_if_expr_with_enum_value() {
|
||||
ret := foo(if get() == .a { .b } else { .a })
|
||||
println(ret)
|
||||
assert ret == 'b'
|
||||
}
|
Loading…
Reference in New Issue