From 7622ff3f546f2b5325ea74c3e5c9c0b47318672d Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 1 Jan 2022 15:15:43 +0800 Subject: [PATCH] checker: check using const var as function (#13006) --- vlib/v/checker/fn.v | 10 ++++++---- vlib/v/checker/tests/unknown_function.out | 6 ++++++ vlib/v/checker/tests/unknown_function.vv | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 vlib/v/checker/tests/unknown_function.out create mode 100644 vlib/v/checker/tests/unknown_function.vv diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 5bdd212ddc..24ff4ad7e6 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -637,10 +637,12 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) // global fn? if !found { if obj := c.file.global_scope.find(fn_name) { - sym := c.table.sym(obj.typ) - if sym.kind == .function { - found = true - func = (sym.info as ast.FnType).func + if obj.typ != 0 { + sym := c.table.sym(obj.typ) + if sym.kind == .function { + found = true + func = (sym.info as ast.FnType).func + } } } } diff --git a/vlib/v/checker/tests/unknown_function.out b/vlib/v/checker/tests/unknown_function.out new file mode 100644 index 0000000000..955d354fd1 --- /dev/null +++ b/vlib/v/checker/tests/unknown_function.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/unknown_function.vv:4:15: error: unknown function: math.max_i64 + 2 | + 3 | fn main() { + 4 | println(math.max_i64()) + | ~~~~~~~~~ + 5 | } diff --git a/vlib/v/checker/tests/unknown_function.vv b/vlib/v/checker/tests/unknown_function.vv new file mode 100644 index 0000000000..08021c5e53 --- /dev/null +++ b/vlib/v/checker/tests/unknown_function.vv @@ -0,0 +1,5 @@ +import math + +fn main() { + println(math.max_i64()) +}