v2: allow type with str method to be used as fn string argument
parent
c099cd8bf6
commit
e7e2c68d09
|
@ -157,6 +157,10 @@ pub fn (c mut Checker) call_expr(call_expr ast.CallExpr) table.Type {
|
||||||
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)
|
||||||
if !c.table.check(typ, arg.typ) {
|
if !c.table.check(typ, arg.typ) {
|
||||||
|
// str method, allow type with str method if fn arg is string
|
||||||
|
if table.type_idx(arg.typ) == table.string_type_idx && typ_sym.has_method('str') {
|
||||||
|
break
|
||||||
|
}
|
||||||
c.error('!cannot use type `$typ_sym.name` as type `$arg_typ_sym.name` in argument ${i+1} to `$fn_name`', call_expr.pos)
|
c.error('!cannot use type `$typ_sym.name` as type `$arg_typ_sym.name` in argument ${i+1} to `$fn_name`', call_expr.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue