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

compiler: check if-expressions returning only one type

This commit is contained in:
Henrixounez 2019-09-04 20:46:25 +02:00 committed by Alexander Medvednikov
parent 818bea34a4
commit 726fcb5eec

View File

@ -3073,9 +3073,11 @@ fn (p mut Parser) if_st(is_expr bool, elif_depth int) string {
}
p.check(.lcbr)
// statements() returns the type of the last statement
first_typ := typ
typ = p.statements()
p.inside_if_expr = false
if is_expr {
p.check_types(first_typ, typ)
p.gen(strings.repeat(`)`, elif_depth + 1))
}
else_returns := p.returns