From 7458927593751055261f4bb14553c32807c20ec8 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 25 Jun 2021 20:26:24 +0300 Subject: [PATCH] checker: fix global fn calls --- vlib/v/ast/scope.v | 2 ++ vlib/v/checker/checker.v | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/vlib/v/ast/scope.v b/vlib/v/ast/scope.v index 96017c6c94..31bc3d1d72 100644 --- a/vlib/v/ast/scope.v +++ b/vlib/v/ast/scope.v @@ -28,12 +28,14 @@ pub fn (s &Scope) free() { } } +/* pub fn new_scope(parent &Scope, start_pos int) &Scope { return &Scope{ parent: parent start_pos: start_pos } } +*/ fn (s &Scope) dont_lookup_parent() bool { return isnil(s.parent) || s.detached_from_parent diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 54395f100f..8340ddbadf 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2407,6 +2407,15 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type { } } } + // global fn? + if !found { + if obj := c.file.global_scope.find(fn_name) { + sym := c.table.get_type_symbol(obj.typ) + if sym.kind == .function { + found = true + } + } + } if !found { c.error('unknown function: $fn_name', call_expr.pos) return ast.void_type