compiler: check if-expressions returning only one type

pull/1873/head
Henrixounez 2019-09-04 20:46:25 +02:00 committed by Alexander Medvednikov
parent 818bea34a4
commit 726fcb5eec
1 changed files with 2 additions and 0 deletions

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