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:
parent
72bbec89a9
commit
296e736f5b
@ -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 { '' }
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user