checker: minor fixes

pull/3793/head
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)
}
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 { '' }

View File

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

View File

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

View File

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