mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
4ef6e16e3b
commit
d0702f3897
@ -62,7 +62,7 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
||||
} else {
|
||||
// check condition type is boolean
|
||||
c.expected_type = ast.bool_type
|
||||
cond_typ := c.unwrap_generic(c.expr(branch.cond))
|
||||
cond_typ := c.table.unaliased_type(c.unwrap_generic(c.expr(branch.cond)))
|
||||
if (cond_typ.idx() != ast.bool_type_idx || cond_typ.has_flag(.option)
|
||||
|| cond_typ.has_flag(.result)) && !c.pref.translated && !c.file.is_translated {
|
||||
c.error('non-bool type `${c.table.type_to_str(cond_typ)}` used as if condition',
|
||||
|
14
vlib/v/tests/if_cond_with_alias_test.v
Normal file
14
vlib/v/tests/if_cond_with_alias_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
type BOOL = bool
|
||||
|
||||
fn example() BOOL {
|
||||
return true
|
||||
}
|
||||
|
||||
fn test_if_cond_with_alias() {
|
||||
if example() {
|
||||
println('Should work, or not?')
|
||||
assert true
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user