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

@ -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 {

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
} }