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 time
import v.cflag import v.cflag
import v.pref import v.pref
import v.util
import term import term
const ( 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 { ast.CallExpr {
if it.return_type.flag_is(.optional) { if it.return_type.flag_is(.optional) {
c.check_or_block(it, xtype, is_return_used) 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 {} else {}

View File

@ -61,9 +61,8 @@ pub fn (mut p Parser) call_expr(is_c, is_js bool, mod string) ast.CallExpr {
// `foo()?` // `foo()?`
p.next() p.next()
is_or_block_used = true is_or_block_used = true
//mut s := ast.Stmt{} // mut s := ast.Stmt{}
//s = ast.ReturnStmt{} // s = ast.ReturnStmt{}
or_stmts << ast.Return{} or_stmts << ast.Return{}
} }
node := ast.CallExpr{ node := ast.CallExpr{