|
|
@ -1839,6 +1839,10 @@ pub fn (mut c Checker) method_call(mut call_expr ast.CallExpr) ast.Type {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
call_expr.return_type = info.return_type
|
|
|
|
call_expr.return_type = info.return_type
|
|
|
|
return info.return_type
|
|
|
|
return info.return_type
|
|
|
|
|
|
|
|
} else if left_type_sym.kind == .char && left_type.nr_muls() == 0 && method_name == 'str' {
|
|
|
|
|
|
|
|
c.error('calling `.str()` on type `char` is not allowed, use its address or cast it to an integer instead',
|
|
|
|
|
|
|
|
call_expr.left.position().extend(call_expr.pos))
|
|
|
|
|
|
|
|
return ast.void_type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mut method := ast.Fn{}
|
|
|
|
mut method := ast.Fn{}
|
|
|
|
mut has_method := false
|
|
|
|
mut has_method := false
|
|
|
@ -2492,11 +2496,15 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
|
|
|
|
c.inside_println_arg = true
|
|
|
|
c.inside_println_arg = true
|
|
|
|
c.expected_type = ast.string_type
|
|
|
|
c.expected_type = ast.string_type
|
|
|
|
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)
|
|
|
|
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)
|
|
|
|
_ := c.check_expr_opt_call(call_expr.args[0].expr, call_expr.args[0].typ)
|
|
|
|
arg := call_expr.args[0]
|
|
|
|
if call_expr.args[0].typ.is_void() {
|
|
|
|
_ := c.check_expr_opt_call(arg.expr, arg.typ)
|
|
|
|
|
|
|
|
if arg.typ.is_void() {
|
|
|
|
c.error('`$fn_name` can not print void expressions', call_expr.pos)
|
|
|
|
c.error('`$fn_name` can not print void expressions', call_expr.pos)
|
|
|
|
|
|
|
|
} else if arg.typ == ast.char_type && arg.typ.nr_muls() == 0 {
|
|
|
|
|
|
|
|
c.error('`$fn_name` cannot print type `char` directly, print its address or cast it to an integer instead',
|
|
|
|
|
|
|
|
call_expr.pos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.fail_if_unreadable(call_expr.args[0].expr, call_expr.args[0].typ, 'argument to print')
|
|
|
|
c.fail_if_unreadable(arg.expr, arg.typ, 'argument to print')
|
|
|
|
c.inside_println_arg = false
|
|
|
|
c.inside_println_arg = false
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
// TODO: optimize `struct T{} fn (t &T) str() string {return 'abc'} mut a := []&T{} a << &T{} println(a[0])`
|
|
|
|
// TODO: optimize `struct T{} fn (t &T) str() string {return 'abc'} mut a := []&T{} a << &T{} println(a[0])`
|
|
|
|