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

checker: set fn arg expected_type

This commit is contained in:
Alexander Medvednikov 2020-03-01 14:10:02 +01:00
parent becd87141c
commit d7a8b1b4f2
2 changed files with 4 additions and 3 deletions

View File

@ -628,15 +628,15 @@ fn (p mut Parser) cast(typ string) {
p.error('cannot cast `bool` to `$typ`')
}
if typ != expr_typ && typ in p.table.sum_types {
T := p.table.find_type(typ)
if expr_typ in T.ctype_names {
tt := p.table.find_type(typ)
if expr_typ in tt.ctype_names {
// There is no need for a cast here, since it was already done
// in p.bool_expression, SUM TYPE CAST2 . Besides, doubling the
// cast here causes MSVC to complain with:
// error C2440: 'type cast': cannot convert from 'ExprType' to 'ExprType'
p.cgen.set_placeholder(pos, '(')
}else{
p.warn('only $T.ctype_names can be casted to `$typ`')
p.warn('only $tt.ctype_names can be casted to `$typ`')
p.error('cannot cast `$expr_typ` to `$typ`')
}
}else{

View File

@ -206,6 +206,7 @@ pub fn (c mut Checker) call_expr(call_expr ast.CallExpr) table.Type {
}
for i, arg_expr in call_expr.args {
arg := if f.is_variadic && i >= f.args.len - 1 { f.args[f.args.len - 1] } else { f.args[i] }
c.expected_type = arg.typ
typ := c.expr(arg_expr)
typ_sym := c.table.get_type_symbol(typ)
arg_typ_sym := c.table.get_type_symbol(arg.typ)