checker: handle unexpected `or` blocks

pull/4895/head
Alexander Medvednikov 2020-05-14 18:19:40 +02:00
parent e5d4786371
commit f49ef39708
3 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,6 @@ import os
import time
import v.cflag
import v.pref
import v.util
import term
const (

View File

@ -935,6 +935,9 @@ pub fn (mut c Checker) check_expr_opt_call(x ast.Expr, xtype table.Type, is_retu
ast.CallExpr {
if it.return_type.flag_is(.optional) {
c.check_or_block(it, xtype, is_return_used)
} else if it.or_block.is_used {
c.error('unexpected `or` block, the function does not return an optional',
it.pos)
}
}
else {}

View File

@ -63,7 +63,6 @@ pub fn (mut p Parser) call_expr(is_c, is_js bool, mod string) ast.CallExpr {
is_or_block_used = true
// mut s := ast.Stmt{}
// s = ast.ReturnStmt{}
or_stmts << ast.Return{}
}
node := ast.CallExpr{