parser/checker: fix global lookup

pull/5297/head
joe-conigliaro 2020-06-09 17:08:11 +10:00
parent c6573f9005
commit 2799a6f065
3 changed files with 9 additions and 9 deletions

View File

@ -1989,6 +1989,13 @@ pub fn (mut c Checker) ident(mut ident ast.Ident) table.Type {
start_scope := c.file.scope.innermost(ident.pos.pos)
if obj := start_scope.find(ident.name) {
match obj {
ast.GlobalDecl {
ident.kind = .global
ident.info = ast.IdentVar{
typ: it.typ
}
return it.typ
}
ast.Var {
mut typ := it.typ
if typ == 0 {
@ -2031,13 +2038,6 @@ pub fn (mut c Checker) ident(mut ident ast.Ident) table.Type {
}
if obj := c.file.global_scope.find(name) {
match obj {
ast.GlobalDecl {
ident.kind = .global
ident.info = ast.IdentVar{
typ: it.typ
}
return it.typ
}
ast.ConstField {
mut typ := it.typ
if typ == 0 {

View File

@ -103,7 +103,7 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
v_code := tmpl.compile_file(path)
mut scope := &ast.Scope{
start_pos: 0
parent: 0
parent: p.global_scope
}
file := parse_text(v_code, p.table, scope, p.global_scope)
if p.pref.is_verbose {

View File

@ -107,7 +107,7 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
pref: pref
scope: &ast.Scope{
start_pos: 0
parent: 0
parent: global_scope
}
errors: []errors.Error{}
warnings: []errors.Warning{}