From 74cc2b2a683fda84313c6808a75e6717ccee2a83 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Mon, 11 May 2020 14:47:39 +1000 Subject: [PATCH] table: add function return type check --- vlib/v/table/table.v | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 4970335921..55c26bc603 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -530,9 +530,13 @@ pub fn (t &Table) check(got, expected Type) bool { if got_type_sym.kind == .function && exp_type_sym.kind == .function { got_info := got_type_sym.info as FnType exp_info := exp_type_sym.info as FnType - if got_info.func.args.len == exp_info.func.args.len { - for i, got_arg in got_info.func.args { - exp_arg := exp_info.func.args[i] + got_fn := got_info.func + exp_fn := exp_info.func + // we are using check() to compare return type & args as they might include + // functions themselves. TODO: optimize, only use check() when needed + if got_fn.args.len == exp_fn.args.len && t.check(got_fn.return_type, exp_fn.return_type) { + for i, got_arg in got_fn.args { + exp_arg := exp_fn.args[i] if !t.check(got_arg.typ, exp_arg.typ) { return false }