From 2799a6f06561d8dbb5b0b721dc324f7ac62413c4 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Tue, 9 Jun 2020 17:08:11 +1000 Subject: [PATCH] parser/checker: fix global lookup --- vlib/v/checker/checker.v | 14 +++++++------- vlib/v/parser/comptime.v | 2 +- vlib/v/parser/parser.v | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index bfad2331ec..c4ca5c16a5 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 { diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 3b008fba1a..4b4fa0e7ee 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -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 { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index fb132f01ce..fa597e58a0 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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{}