From 0161e51df7f8aed8406e964316eb98926a52c023 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Thu, 24 Dec 2020 19:56:15 +0800 Subject: =?UTF-8?q?=E9=92=88=E5=AF=B9generic=EF=BC=8C=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=85=81=E8=AE=B8=E6=98=AF=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E5=AD=97=E9=9D=A2=E5=80=BC=E6=9D=A5=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/diagnostics/init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index cfd0f4cb..5fdc3891 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -945,3 +945,19 @@ v2 = v v2:method1() v2:method2() -- 这个感觉实际应该报错更合适 ]] + +TEST [[ +---@generic T +---@param arg1 T +---@return T +function Generic(arg1) return arg1 end + +---@class Foo +---@field bar1 integer +local Foo = {} + +local v1 = Generic("Foo") +print(v1.bar1) +local v2 = Generic(Foo) +print(v2.bar1) +]] -- cgit v1.2.3 From 9586b303e9b76d5da19352bd42599480c0f2c0d1 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Mon, 28 Dec 2020 15:44:08 +0800 Subject: =?UTF-8?q?=E4=BD=BF=E7=94=A8=20---@param=20arg=20`T`=20=E6=9D=A5?= =?UTF-8?q?=E5=AE=8C=E6=88=90'=E7=B1=BB=E5=9E=8B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=98=AF=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=AD=97?= =?UTF-8?q?=E9=9D=A2=E5=80=BC=E6=9D=A5=E8=A1=A8=E8=BE=BE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/definition/luadoc.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++ test/diagnostics/init.lua | 16 ------------- 2 files changed, 56 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua index 4a23b2ac..1f3dae00 100644 --- a/test/definition/luadoc.lua +++ b/test/definition/luadoc.lua @@ -197,3 +197,59 @@ TEST [[ ---@type Cat local ?> ]] + +TEST [[ +---@class Foo +local Foo = {} +function Foo:() end + +---@generic T +---@param arg1 T +---@return T +function Generic(arg1) print(arg1) end + +local v1 = Generic(Foo) +print(v1.) +]] + +TEST [[ +---@class Foo +local Foo = {} +function Foo:bar1() end + +---@generic T +---@param arg1 T +---@return T +function Generic(arg1) print(arg1) end + +local v1 = Generic("Foo") +print(v1.) +]] + +TEST [[ +---@class Foo +local Foo = {} +function Foo:bar1() end + +---@generic T +---@param arg1 `T` +---@return T +function Generic(arg1) print(arg1) end + +local v1 = Generic(Foo) +print(v1.) +]] + +TEST [[ +---@class Foo +local Foo = {} +function Foo:() end + +---@generic T +---@param arg1 `T` +---@return T +function Generic(arg1) print(arg1) end + +local v1 = Generic("Foo") +print(v1.) +]] diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index c593968e..4e485d2a 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -960,19 +960,3 @@ print(T1.f1) T2 = {} print(T2.) ]] - -TEST [[ ----@generic T ----@param arg1 T ----@return T -function Generic(arg1) return arg1 end - ----@class Foo ----@field bar1 integer -local Foo = {} - -local v1 = Generic("Foo") -print(v1.bar1) -local v2 = Generic(Foo) -print(v2.bar1) -]] -- cgit v1.2.3