checker: set fn arg expected_type
							parent
							
								
									becd87141c
								
							
						
					
					
						commit
						d7a8b1b4f2
					
				| 
						 | 
					@ -628,15 +628,15 @@ fn (p mut Parser) cast(typ string) {
 | 
				
			||||||
			p.error('cannot cast `bool` to `$typ`')
 | 
								p.error('cannot cast `bool` to `$typ`')
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if typ != expr_typ && typ in p.table.sum_types {
 | 
							if typ != expr_typ && typ in p.table.sum_types {
 | 
				
			||||||
			T := p.table.find_type(typ)
 | 
								tt := p.table.find_type(typ)
 | 
				
			||||||
			if expr_typ in T.ctype_names {
 | 
								if expr_typ in tt.ctype_names {
 | 
				
			||||||
				// There is no need for a cast here, since it was already done
 | 
									// There is no need for a cast here, since it was already done
 | 
				
			||||||
				// in p.bool_expression, SUM TYPE CAST2 . Besides, doubling the
 | 
									// in p.bool_expression, SUM TYPE CAST2 . Besides, doubling the
 | 
				
			||||||
				// cast here causes MSVC to complain with:
 | 
									// cast here causes MSVC to complain with:
 | 
				
			||||||
				// error C2440: 'type cast': cannot convert from 'ExprType' to 'ExprType'
 | 
									// error C2440: 'type cast': cannot convert from 'ExprType' to 'ExprType'
 | 
				
			||||||
				p.cgen.set_placeholder(pos, '(')
 | 
									p.cgen.set_placeholder(pos, '(')
 | 
				
			||||||
			}else{
 | 
								}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`')
 | 
									p.error('cannot cast `$expr_typ` to `$typ`')
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}else{
 | 
							}else{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 {
 | 
						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] }
 | 
							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 := c.expr(arg_expr)
 | 
				
			||||||
		typ_sym := c.table.get_type_symbol(typ)
 | 
							typ_sym := c.table.get_type_symbol(typ)
 | 
				
			||||||
		arg_typ_sym := c.table.get_type_symbol(arg.typ)
 | 
							arg_typ_sym := c.table.get_type_symbol(arg.typ)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue