diff --git a/cmd/v/simple_tool.v b/cmd/v/simple_tool.v index f595554746..e69e463d7a 100644 --- a/cmd/v/simple_tool.v +++ b/cmd/v/simple_tool.v @@ -20,7 +20,6 @@ fn launch_tool(is_verbose bool, tname string, cmdname string) { tname_index = os.args.len } mut compilation_options := os.args[1..tname_index].clone() - //f := os.args.join(' ') tool_args := os.args[1..].join(' ') tool_exe := path_of_executable(os.realpath('$vroot/cmd/tools/$tname')) tool_source := os.realpath('$vroot/cmd/tools/${tname}.v') diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index bdf60f3959..7758a18146 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -212,21 +212,23 @@ pub fn (c mut Checker) call_expr(call_expr ast.CallExpr) table.Type { pub fn (c mut Checker) check_method_call_expr(method_call_expr ast.MethodCallExpr) table.Type { typ := c.expr(method_call_expr.expr) typ_sym := c.table.get_type_symbol(typ) - if method := typ_sym.find_method(method_call_expr.name) { + name := method_call_expr.name + if method := typ_sym.find_method(name) { return method.return_type } + if typ_sym.kind == .array && name in ['filter', 'clone'] { + // info := typ_sym.info as table.Array + return typ // info.elem_type + } // check parent if typ_sym.parent_idx != 0 { parent := &c.table.types[typ_sym.parent_idx] - if method := parent.find_method(method_call_expr.name) { + if method := parent.find_method(name) { + // println('got method $name, returning') return method.return_type } } - if typ_sym.kind == .array && method_call_expr.name == 'filter' { - // info := typ_sym.info as table.Array - return typ // info.elem_type - } - c.error('type `$typ_sym.name` has no method `$method_call_expr.name`', method_call_expr.pos) + c.error('type `$typ_sym.name` has no method `$name`', method_call_expr.pos) return table.void_type } diff --git a/vlib/v/gen/tests/1.vv b/vlib/v/gen/tests/1.vv index 83b7adb1c5..1a7a629c6f 100644 --- a/vlib/v/gen/tests/1.vv +++ b/vlib/v/gen/tests/1.vv @@ -71,6 +71,9 @@ fn foo(a int) { q := true || false b2 := bools[0] || true b3 := get_bool() || true + //cloned = nums.clone() + //cloned1 := cloned[0] + //println(cloned1 == 1) } fn get_int(a string) int { diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 5f2a6207d2..cbc9fa21a3 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -18,6 +18,7 @@ pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { name: fn_name args: args // tok: tok + pos: tok.position() is_c: is_c } @@ -131,8 +132,10 @@ fn (p mut Parser) fn_decl() ast.FnDecl { typ = p.parse_type() } p.return_type = typ + // Register if is_method { type_sym := p.table.get_type_symbol(rec_type) + // p.warn('reg method $type_sym.name . $name ()') ok := p.table.register_method(type_sym, table.Fn{ name: name args: args diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 0b697a1d09..15f0cd4551 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -86,6 +86,7 @@ pub fn (t mut Table) register_fn(new_fn Fn) { pub fn (t &Table) register_method(typ &TypeSymbol, new_fn Fn) bool { // println('register method `$new_fn.name` type=$typ.name idx=$typ.idx') // println('register method `$new_fn.name` type=$typ.name') + // TODO mut << bug mut t1 := typ mut methods := typ.methods methods << new_fn