From 3f6ccd3120b62077d5723309cc471a223d4daacb Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 10 Feb 2020 13:58:24 +0100 Subject: [PATCH] v2: minor fixes --- cmd/v/compile_options.v | 2 +- vlib/v/checker/checker.v | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/v/compile_options.v b/cmd/v/compile_options.v index 448b62803f..8a9bf686bf 100644 --- a/cmd/v/compile_options.v +++ b/cmd/v/compile_options.v @@ -142,7 +142,7 @@ pub fn new_v(args []string) &compiler.V { build_mode: build_mode cflags: cflags ccompiler: ccompiler - building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || rdir_name == 'vfmt.v' || rdir_name == 'cmd/v' || dir.contains('vlib')) + building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v' || rdir_name == 'vfmt.v' || rdir_name == 'cmd/v' || dir.contains('vlib')) // is_fmt: comptime_define == 'vfmt' user_mod_path: user_mod_path diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index afbd75d936..698acda685 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -78,7 +78,7 @@ fn (c &Checker) complete_types() { info.key_type = c.resolve(info.key_type) updated = true } - if table.type_is_unresolved(info.value_type) { + if table.type_is_unresolved(info.value_type) { info.value_type = c.resolve(info.value_type) updated = true } @@ -111,13 +111,13 @@ fn (c &Checker) complete_types() { // return the resolved Type from unresovled Type pub fn (c &Checker) resolve(unresolved table.Type) table.Type { - return c.resolved[-table.type_idx(unresolved)-1] + return c.resolved[-table.type_idx(unresolved) - 1] } pub fn (c &Checker) check_struct_init(struct_init ast.StructInit) table.Type { // typ := c.table.find_type(struct_init.typ.typ.name) or { - // c.error('unknown struct: $struct_init.typ.typ.name', struct_init.pos) - // panic('') + // c.error('unknown struct: $struct_init.typ.typ.name', struct_init.pos) + // panic('') // } typ := c.table.get_type_symbol(struct_init.typ) match typ.kind { @@ -171,29 +171,24 @@ pub fn (c &Checker) call_expr(call_expr ast.CallExpr) table.Type { fn_name := call_expr.name if f := c.table.find_fn(fn_name) { // return_ti := f.return_ti - if /*TODO:*/!f.is_c { - if call_expr.args.len < f.args.len { - c.error('too few arguments in call to `$fn_name`', call_expr.pos) - } - else if !f.is_variadic && call_expr.args.len > f.args.len { - c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos) - } + if f.is_c { + return f.return_type + } + if call_expr.args.len < f.args.len { + c.error('too few arguments in call to `$fn_name`', call_expr.pos) + } + else if !f.is_variadic && call_expr.args.len > f.args.len { + c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos) } - if /*TODO:*/!f.is_c { for i, arg_expr in call_expr.args { - arg := if f.is_variadic && i >= f.args.len-1 { - f.args[f.args.len-1] - } else { - f.args[i] - } + arg := if f.is_variadic && i >= f.args.len - 1 { f.args[f.args.len - 1] } else { f.args[i] } typ := c.expr(arg_expr) typ_sym := c.table.get_type_symbol(typ) arg_typ_sym := c.table.get_type_symbol(arg.typ) - if /*TODO:*/!f.is_c && !c.table.check(typ, arg.typ) { + if !c.table.check(typ, arg.typ) { c.error('!cannot use type `$typ_sym.name` as type `$arg_typ_sym.name` in argument ${i+1} to `$fn_name`', call_expr.pos) } } - } return f.return_type } c.error('unknown fn: $fn_name', call_expr.pos)