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

v2: temp const fix

This commit is contained in:
joe-conigliaro 2020-02-22 23:04:56 +11:00
parent 6f577321f1
commit 30c8a5a010
3 changed files with 16 additions and 2 deletions

View File

@ -213,6 +213,7 @@ pub:
imports []Import
stmts []Stmt
scope &Scope
const_decls []ConstDecl
}
pub struct IdentFunc {

View File

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

View File

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