parser: panic and exit count as returns

pull/1527/head
Julian Schurhammer 2019-08-09 18:17:31 +12:00 committed by Alexander Medvednikov
parent fbc480fbed
commit 6a9bda806f
1 changed files with 14 additions and 4 deletions

View File

@ -1130,6 +1130,10 @@ fn (p mut Parser) statement(add_semi bool) string {
p.js_decode() p.js_decode()
} }
else { else {
// panic and exit count as returns since they stop the function
if p.lit == 'panic' || p.lit == 'exit' {
p.returns = true
}
// `a + 3`, `a(7)` or maybe just `a` // `a + 3`, `a(7)` or maybe just `a`
q = p.bool_expression() q = p.bool_expression()
} }
@ -2945,11 +2949,17 @@ fn (p mut Parser) if_st(is_expr bool, elif_depth int) string {
if p.tok == .key_if { if p.tok == .key_if {
if is_expr { if is_expr {
p.gen(') : (') p.gen(') : (')
return p.if_st(is_expr, elif_depth + 1) nested := p.if_st(is_expr, elif_depth + 1)
nested_returns := p.returns
p.returns = if_returns && nested_returns
return nested
} }
else { else {
p.gen(' else ') p.gen(' else ')
return p.if_st(is_expr, 0) nested := p.if_st(is_expr, 0)
nested_returns := p.returns
p.returns = if_returns && nested_returns
return nested
} }
// return '' // return ''
} }
@ -2966,10 +2976,10 @@ fn (p mut Parser) if_st(is_expr bool, elif_depth int) string {
if is_expr { if is_expr {
p.gen(strings.repeat(`)`, elif_depth + 1)) p.gen(strings.repeat(`)`, elif_depth + 1))
} }
return typ
}
else_returns := p.returns else_returns := p.returns
p.returns = if_returns && else_returns p.returns = if_returns && else_returns
return typ
}
p.inside_if_expr = false p.inside_if_expr = false
if p.fileis('test_test') { if p.fileis('test_test') {
println('if ret typ="$typ" line=$p.scanner.line_nr') println('if ret typ="$typ" line=$p.scanner.line_nr')