From 296e736f5b8c9262718dec9936366fee5e095ac5 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 20 Feb 2020 15:42:56 +0100 Subject: [PATCH] checker: minor fixes --- cmd/v/compile_options.v | 2 +- vlib/v/checker/checker.v | 9 +++++++++ vlib/v/parser/parser.v | 27 +++++++++++---------------- vlib/v/table/table.v | 3 +-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/cmd/v/compile_options.v b/cmd/v/compile_options.v index d94ded7f73..cc76381c28 100644 --- a/cmd/v/compile_options.v +++ b/cmd/v/compile_options.v @@ -37,7 +37,7 @@ pub fn new_v(args []string) &compiler.V { exit(1) } mut out_name := cmdline.option(args, '-o', '') - mut dir := args.last() + mut dir := args[args.len-1]//.last() if 'run' in args { args_after_run := cmdline.only_non_options( cmdline.options_after(args,['run']) ) dir = if args_after_run.len>0 { args_after_run[0] } else { '' } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 792d88711f..6a5ddbd31c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -50,6 +50,7 @@ pub fn (c mut Checker) check_struct_init(struct_init ast.StructInit) table.Type // panic('') // } typ_sym := c.table.get_type_symbol(struct_init.typ) + // println('check struct $typ_sym.name') match typ_sym.kind { .placeholder { c.error('unknown struct: $typ_sym.name', struct_init.pos) @@ -161,6 +162,10 @@ pub fn (c mut Checker) call_expr(call_expr ast.CallExpr) table.Type { if arg_typ_sym.kind == .string && typ_sym.has_method('str') { continue } + // TODO const bug + if typ_sym.kind == .void && arg_typ_sym.kind == .string { + continue + } c.error('!cannot use type `$typ_sym.name` as type `$arg_typ_sym.name` in argument ${i+1} to `$fn_name`', call_expr.pos) } } @@ -199,6 +204,10 @@ pub fn (c mut Checker) selector_expr(selector_expr ast.SelectorExpr) table.Type } } if typ_sym.kind != .struct_ { + if field_name == 'default_mode' { + // TODO + return table.bool_type + } c.error('`$typ_sym.name` is not a struct', selector_expr.pos) } else { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 160f75144c..118d32a42c 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -56,7 +56,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt { pref: &pref.Preferences{} scope: scope // scope: &ast.Scope{start_pos: 0, parent: 0} - + } p.init_parse_fns() p.read_first_token() @@ -320,7 +320,7 @@ pub fn (p mut Parser) stmt() ast.Stmt { return ast.ExprStmt{ expr: expr // typ: typ - + } } } @@ -640,7 +640,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) { .key_none { p.next() typ = table.none_type - node = ast.None {} + node = ast.None{} } .key_sizeof { p.next() // sizeof @@ -705,13 +705,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) { node = p.dot_expr(node, typ) } else if p.tok.kind == .lsbr { - node = p.index_expr(node) // , typ) - /* - ie_node,ie_typ := p.index_expr(node, typ) - node = ie_node - typ = ie_typ - */ - + node = p.index_expr(node) } else if p.tok.kind == .key_as { p.next() @@ -886,6 +880,7 @@ fn (p &Parser) is_addative() bool { } */ // `.green` +// `pref.BuildMode.default_mode` fn (p mut Parser) enum_val() (ast.Expr,table.Type) { p.check(.dot) name := p.check_name() @@ -893,7 +888,7 @@ fn (p mut Parser) enum_val() (ast.Expr,table.Type) { node = ast.EnumVal{ name: name } - return node,table.bool_type + return node,table.int_type } fn (p mut Parser) for_statement() ast.Stmt { @@ -1075,10 +1070,10 @@ fn (p mut Parser) if_expr() ast.Expr { stmts: stmts else_stmts: else_stmts // typ: typ - + pos: pos // left: left - + } return node } @@ -1466,10 +1461,10 @@ fn (p mut Parser) var_decl() ast.VarDecl { node := ast.VarDecl{ name: name expr: expr // p.expr(token.lowest_prec) - + is_mut: is_mut // typ: typ - + pos: p.tok.position() } p.scope.register_var(node) @@ -1588,7 +1583,7 @@ fn (p mut Parser) match_expr() ast.Expr { blocks: blocks match_exprs: match_exprs // typ: typ - + cond: cond } return node diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 8d5d35d046..b419bb972a 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -222,7 +222,7 @@ pub fn (t mut Table) register_type_symbol(typ TypeSymbol) int { match ex_type.kind { .placeholder { // override placeholder - println('overriding type placeholder `$typ.name`') + // println('overriding type placeholder `$typ.name`') t.types[existing_idx] = { typ | methods:ex_type.methods @@ -394,4 +394,3 @@ pub fn (t &Table) check(got, expected Type) bool { } return true } -