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

v2: handle unresolved consts

This commit is contained in:
Alexander Medvednikov 2020-02-10 18:42:53 +01:00
parent bf5ed5e451
commit d5f90ef64b
5 changed files with 25 additions and 9 deletions

View File

@ -384,6 +384,13 @@ pub fn (c &Checker) expr(node ast.Expr) table.Type {
} }
return info.typ return info.typ
} }
// Handle indents with unresolved types during the parsing step
// (declared after first usage)
else if it.kind == .blank_ident {
if constant := c.table.find_const(it.name) {
return constant.typ
}
}
return table.void_type return table.void_type
} }
ast.BoolLiteral { ast.BoolLiteral {

View File

@ -33,7 +33,7 @@ fn test_c_files() {
} }
else { else {
eprintln('${term_fail} ${i}') eprintln('${term_fail} ${i}')
eprintln('${path}: got\n{$res}') eprintln('${path}: got\n$res')
assert false assert false
} }
} }

View File

@ -8,7 +8,7 @@ void variadic(variadic_int a);
void ensure_cap(int required, int cap); void ensure_cap(int required, int cap);
void println(string s); void println(string s);
void matches(); void matches();
void end();
int pi = 3; int pi = 3;
typedef struct { typedef struct {
@ -30,7 +30,6 @@ int main() {
void foo(int a) { void foo(int a) {
while (true) { while (true) {
} }
for (int i = 0; for (int i = 0;
i < 10; i++; i < 10; i++;
@ -92,6 +91,7 @@ multi_return_int_string multi_return() {
} }
void variadic(variadic_int a) { void variadic(variadic_int a) {
int x = path_sep;
} }
void ensure_cap(int required, int cap) { void ensure_cap(int required, int cap) {
@ -115,6 +115,9 @@ void matches() {
} }
; ;
}
} }
int path_sep = 10;
void end() {
}

View File

@ -97,7 +97,7 @@ fn multi_return() (int,string) {
} }
fn variadic(a ...int) { fn variadic(a ...int) {
//a := path_sep x := path_sep
} }
fn ensure_cap(required int, cap int) { fn ensure_cap(required int, cap int) {
@ -120,10 +120,12 @@ fn matches() {
} }
} }
/*
const ( const (
path_sep = 10 path_sep = 10
) )
*/
fn end() {
}

View File

@ -437,8 +437,12 @@ pub fn (p mut Parser) parse_ident(is_c bool) (ast.Ident,table.Type) {
// Function object (not a call), e.g. `onclick(my_click)` // Function object (not a call), e.g. `onclick(my_click)`
p.table.find_fn(name) or { p.table.find_fn(name) or {
// ident.info = ast.IdentVar // ident.info = ast.IdentVar
p.error('parse_ident: unknown identifier `$name`') node = ast.Ident{
exit(0) kind: .blank_ident
name: name
}
return node,typ
// p.error('parse_ident: unknown identifier `$name`')
} }
// p.next() // p.next()
} }