From 30c8a5a010056fc8b2341f717eee3dcffe32b6ca Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Sat, 22 Feb 2020 23:04:56 +1100 Subject: [PATCH] v2: temp const fix --- vlib/v/ast/ast.v | 1 + vlib/v/checker/checker.v | 13 +++++++++++++ vlib/v/parser/parser.v | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 38de987113..0f2b314110 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -213,6 +213,7 @@ pub: imports []Import stmts []Stmt scope &Scope + const_decls []ConstDecl } pub struct IdentFunc { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 1d957b91e7..ceb90e25eb 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -48,6 +48,18 @@ pub fn (c mut Checker) check2(ast_file ast.File) []string { } pub fn (c mut Checker) check_files(ast_files []ast.File) { + // TODO: temp fix, impl proper solition + for file in ast_files { + c.file = file + for stmt in file.stmts { + match mut stmt { + ast.ConstDecl { + c.stmt(*it) + } + else {} + } + } + } for file in ast_files { c.check(file) } @@ -304,6 +316,7 @@ fn (c mut Checker) stmt(node ast.Stmt) { mut field := it.fields[i] typ := c.expr(expr) mut xconst := c.table.consts[field.name] + // if xconst.typ == 0 { xconst.typ = typ c.table.consts[field.name] = xconst diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 906fd536fd..a337576ccf 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -466,7 +466,7 @@ pub fn (p mut Parser) parse_ident(is_c bool) ast.Ident { else { // handle consts/fns in checker ident.kind = .unresolved - return ident + return {ident | name: p.prepend_mod(name)} } } @@ -1277,7 +1277,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl { mut fields := []ast.Field mut exprs := []ast.Expr for p.tok.kind != .rpar { - name := p.check_name() + name := p.prepend_mod(p.check_name()) // println('const: $name') p.check(.assign) expr,typ := p.expr(0)