From 96b320247788163f7d014404b7b1f089aed82dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sun, 23 Oct 2022 02:21:17 +0800 Subject: infer type by function as parameters resolve #1153 --- test/type_inference/init.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'test/type_inference/init.lua') diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 43177dc7..de42a91d 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3803,3 +3803,58 @@ local class class.has.nested.() ]] + +TEST 'integer[]' [[ +---@generic T +---@param f fun(x: T) +---@return T[] +local function x(f) end + +---@param x integer +local = x(function (x) end) +]] + +TEST 'integer[]' [[ +---@generic T +---@param f fun():T +---@return T[] +local function x(f) end + +local = x(function () + return 1 +end) +]] + +TEST 'integer[]' [[ +---@generic T +---@param f fun():T +---@return T[] +local function x(f) end + +---@return integer +local = x(function () end) +]] + +TEST 'integer[]' [[ +---@generic T +---@param f fun(x: T) +---@return T[] +local function x(f) end + +---@type fun(x: integer) +local cb + +local = x(cb) +]] + +TEST 'integer[]' [[ +---@generic T +---@param f fun():T +---@return T[] +local function x(f) end + +---@type fun(): integer +local cb + +local = x(cb) +]] -- cgit v1.2.3