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

checker: fn arg - disallow any type with .str() to be passed as string

This commit is contained in:
joe-conigliaro 2020-06-23 08:51:18 +10:00
parent 837df7c074
commit cff2874608
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -851,9 +851,9 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
if !c.check_types(got_arg_typ, exp_arg_typ) { if !c.check_types(got_arg_typ, exp_arg_typ) {
got_arg_sym := c.table.get_type_symbol(got_arg_typ) got_arg_sym := c.table.get_type_symbol(got_arg_typ)
// str method, allow type with str method if fn arg is string // str method, allow type with str method if fn arg is string
if exp_arg_sym.kind == .string && got_arg_sym.has_method('str') { // if exp_arg_sym.kind == .string && got_arg_sym.has_method('str') {
continue // continue
} // }
if got_arg_typ != table.void_type { if got_arg_typ != table.void_type {
c.error('cannot use type `$got_arg_sym.str()` as type `$exp_arg_sym.str()` in argument ${i+1} to `${left_type_sym.name}.$method_name`', c.error('cannot use type `$got_arg_sym.str()` as type `$exp_arg_sym.str()` in argument ${i+1} to `${left_type_sym.name}.$method_name`',
call_expr.pos) call_expr.pos)