1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: minor fixes

This commit is contained in:
Alexander Medvednikov 2020-02-20 15:42:56 +01:00
parent 72bbec89a9
commit 296e736f5b
4 changed files with 22 additions and 19 deletions

View File

@ -37,7 +37,7 @@ pub fn new_v(args []string) &compiler.V {
exit(1) exit(1)
} }
mut out_name := cmdline.option(args, '-o', '') mut out_name := cmdline.option(args, '-o', '')
mut dir := args.last() mut dir := args[args.len-1]//.last()
if 'run' in args { if 'run' in args {
args_after_run := cmdline.only_non_options( cmdline.options_after(args,['run']) ) args_after_run := cmdline.only_non_options( cmdline.options_after(args,['run']) )
dir = if args_after_run.len>0 { args_after_run[0] } else { '' } dir = if args_after_run.len>0 { args_after_run[0] } else { '' }

View File

@ -50,6 +50,7 @@ pub fn (c mut Checker) check_struct_init(struct_init ast.StructInit) table.Type
// panic('') // panic('')
// } // }
typ_sym := c.table.get_type_symbol(struct_init.typ) typ_sym := c.table.get_type_symbol(struct_init.typ)
// println('check struct $typ_sym.name')
match typ_sym.kind { match typ_sym.kind {
.placeholder { .placeholder {
c.error('unknown struct: $typ_sym.name', struct_init.pos) 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') { if arg_typ_sym.kind == .string && typ_sym.has_method('str') {
continue 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) 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 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) c.error('`$typ_sym.name` is not a struct', selector_expr.pos)
} }
else { else {

View File

@ -56,7 +56,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
pref: &pref.Preferences{} pref: &pref.Preferences{}
scope: scope scope: scope
// scope: &ast.Scope{start_pos: 0, parent: 0} // scope: &ast.Scope{start_pos: 0, parent: 0}
} }
p.init_parse_fns() p.init_parse_fns()
p.read_first_token() p.read_first_token()
@ -320,7 +320,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
return ast.ExprStmt{ return ast.ExprStmt{
expr: expr expr: expr
// typ: typ // typ: typ
} }
} }
} }
@ -640,7 +640,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
.key_none { .key_none {
p.next() p.next()
typ = table.none_type typ = table.none_type
node = ast.None {} node = ast.None{}
} }
.key_sizeof { .key_sizeof {
p.next() // 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) node = p.dot_expr(node, typ)
} }
else if p.tok.kind == .lsbr { else if p.tok.kind == .lsbr {
node = p.index_expr(node) // , typ) node = p.index_expr(node)
/*
ie_node,ie_typ := p.index_expr(node, typ)
node = ie_node
typ = ie_typ
*/
} }
else if p.tok.kind == .key_as { else if p.tok.kind == .key_as {
p.next() p.next()
@ -886,6 +880,7 @@ fn (p &Parser) is_addative() bool {
} }
*/ */
// `.green` // `.green`
// `pref.BuildMode.default_mode`
fn (p mut Parser) enum_val() (ast.Expr,table.Type) { fn (p mut Parser) enum_val() (ast.Expr,table.Type) {
p.check(.dot) p.check(.dot)
name := p.check_name() name := p.check_name()
@ -893,7 +888,7 @@ fn (p mut Parser) enum_val() (ast.Expr,table.Type) {
node = ast.EnumVal{ node = ast.EnumVal{
name: name name: name
} }
return node,table.bool_type return node,table.int_type
} }
fn (p mut Parser) for_statement() ast.Stmt { fn (p mut Parser) for_statement() ast.Stmt {
@ -1075,10 +1070,10 @@ fn (p mut Parser) if_expr() ast.Expr {
stmts: stmts stmts: stmts
else_stmts: else_stmts else_stmts: else_stmts
// typ: typ // typ: typ
pos: pos pos: pos
// left: left // left: left
} }
return node return node
} }
@ -1466,10 +1461,10 @@ fn (p mut Parser) var_decl() ast.VarDecl {
node := ast.VarDecl{ node := ast.VarDecl{
name: name name: name
expr: expr // p.expr(token.lowest_prec) expr: expr // p.expr(token.lowest_prec)
is_mut: is_mut is_mut: is_mut
// typ: typ // typ: typ
pos: p.tok.position() pos: p.tok.position()
} }
p.scope.register_var(node) p.scope.register_var(node)
@ -1588,7 +1583,7 @@ fn (p mut Parser) match_expr() ast.Expr {
blocks: blocks blocks: blocks
match_exprs: match_exprs match_exprs: match_exprs
// typ: typ // typ: typ
cond: cond cond: cond
} }
return node return node

View File

@ -222,7 +222,7 @@ pub fn (t mut Table) register_type_symbol(typ TypeSymbol) int {
match ex_type.kind { match ex_type.kind {
.placeholder { .placeholder {
// override placeholder // override placeholder
println('overriding type placeholder `$typ.name`') // println('overriding type placeholder `$typ.name`')
t.types[existing_idx] = { t.types[existing_idx] = {
typ | typ |
methods:ex_type.methods methods:ex_type.methods
@ -394,4 +394,3 @@ pub fn (t &Table) check(got, expected Type) bool {
} }
return true return true
} }