From 0ded390ce1b477e62963e8e67488b00ba8427a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 26 Feb 2021 17:04:38 +0800 Subject: improve infer cross `pairs` --- test/type_inference/init.lua | 53 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'test/type_inference') diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 28bdd0e9..725b19fe 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -471,16 +471,64 @@ local function f() end local = f() ]] +TEST 'string' [[ +---@generic K, V +---@return fun(arg: table):K, V +local function f() end + +local f2 = f() + +---@type table +local t + +local , v = f2(t) +]] + +TEST 'string' [[ +---@generic T: table, K, V +---@param t T +---@return fun(table: table, index: K):K, V +---@return T +---@return nil +local function pairs(t) end + +local f = pairs(t) + +---@type table +local t + +for , v in f, t do +end +]] + +TEST 'boolean' [[ +---@generic T: table, K, V +---@param t T +---@return fun(table: table, index: K):K, V +---@return T +---@return nil +local function pairs(t) end + +local f = pairs(t) + +---@type table +local t + +for k, in f, t do +end +]] + TEST 'string' [[ ---@generic T: table, K, V ---@param t T ---@return fun(table: table, index: K):K, V ---@return T ---@return nil -function pairs(t) end +local function pairs(t) end ---@type table local t + for , v in pairs(t) do end ]] @@ -491,10 +539,11 @@ TEST 'boolean' [[ ---@return fun(table: table, index: K):K, V ---@return T ---@return nil -function pairs(t) end +local function pairs(t) end ---@type table local t + for k, in pairs(t) do end ]] -- cgit v1.2.3