From b1357d9641998ac7fcdbb3e3fd4a3b3b5a4aad21 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 27 Feb 2020 16:51:39 +0100 Subject: [PATCH] v2: checker: fix filter() --- cmd/v/simple_tool.v | 1 + vlib/v/checker/checker.v | 38 +++++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/cmd/v/simple_tool.v b/cmd/v/simple_tool.v index e69e463d7a..f595554746 100644 --- a/cmd/v/simple_tool.v +++ b/cmd/v/simple_tool.v @@ -20,6 +20,7 @@ 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 771fc8342e..bdf60f3959 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -222,6 +222,10 @@ pub fn (c mut Checker) check_method_call_expr(method_call_expr ast.MethodCallExp 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) return table.void_type } @@ -284,25 +288,25 @@ pub fn (c mut Checker) return_stmt(return_stmt ast.Return) { } pub fn (c mut Checker) assign_stmt(assign_stmt ast.AssignStmt) { - // multi return - if assign_stmt.left.len > assign_stmt.right.len { - right := c.expr(assign_stmt.right[0]) - right_sym := c.table.get_type_symbol(right) - info := right_sym.mr_info() - if right_sym.kind != .multi_return { - c.error('wrong number of vars', assign_stmt.pos) - } - mut scope := c.file.scope.innermost(assign_stmt.pos.pos) or { - c.file.scope - } - for i, ident in assign_stmt.left { + // multi return + if assign_stmt.left.len > assign_stmt.right.len { + right := c.expr(assign_stmt.right[0]) + right_sym := c.table.get_type_symbol(right) + info := right_sym.mr_info() + if right_sym.kind != .multi_return { + c.error('wrong number of vars', assign_stmt.pos) + } + mut scope := c.file.scope.innermost(assign_stmt.pos.pos) or { + c.file.scope + } + for i, ident in assign_stmt.left { // TODO: check types scope.override_var(ast.VarDecl{ - name: ident.name - typ: info.types[i] - }) - } - } + name: ident.name + typ: info.types[i] + }) + } + } // TODO: multiple assign }