summaryrefslogtreecommitdiff
path: root/test/definition/luadoc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/definition/luadoc.lua')
-rw-r--r--test/definition/luadoc.lua294
1 files changed, 291 insertions, 3 deletions
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index ff54546b..5531e2e3 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -87,6 +87,11 @@ TEST [[
]]
TEST [[
+---@type <!fun():void!>
+local <?<!f!>?>
+]]
+
+TEST [[
---@param f <!fun():void!>
function t(<?<!f!>?>) end
]]
@@ -97,7 +102,7 @@ function f(<?...?>) end
]]
TEST [[
----@overload fun(y: boolean)
+---@overload <!fun(y: boolean)!>
---@param x number
---@param y boolean
---@param z string
@@ -108,7 +113,7 @@ print(<?f?>)
TEST [[
local function f()
- return 1
+ return <!1!>
end
---@class Class
@@ -204,6 +209,23 @@ TEST [[
]]
TEST [[
+---@return <!fun()!>
+local function f() end
+
+local <?<!r!>?> = f()
+]]
+
+TEST [[
+---@generic T
+---@param p T
+---@return T
+local function f(p) end
+
+local <!k!>
+local <?<!r!>?> = f(<!k!>)
+]]
+
+TEST [[
---@class Foo
local Foo = {}
function Foo:<!bar1!>() end
@@ -260,6 +282,26 @@ print(v1.<?bar1?>)
]]
TEST [[
+---@class A
+local <!t!>
+
+---@type A[]
+local b
+
+local <?<!c!>?> = b[1]
+]]
+
+TEST [[
+---@class A
+local <!t!>
+
+---@type table<number, A>
+local b
+
+local <?<!c!>?> = b[1]
+]]
+
+TEST [[
---@class Foo
local Foo = {}
function Foo:<!bar1!>() end
@@ -299,13 +341,223 @@ print(v1[1].<?bar1?>)
--]]
TEST [[
+---@type fun():<!fun()!>
+local f
+
+local <?<!f2!>?> = f()
+]]
+
+TEST [[
+---@generic T
+---@type fun(x: T):T
+local f
+
+local <?<!v2!>?> = f(<!{}!>)
+]]
+
+TEST [[
+---@generic T
+---@param x T
+---@return fun():T
+local function f(x) end
+
+local v1 = f(<!{}!>)
+local <?<!v2!>?> = v1()
+]]
+
+TEST [[
+---@generic T
+---@type fun(x: T):fun():T
+local f
+
+local v1 = f(<!{}!>)
+local <?<!v2!>?> = v1()
+]]
+
+TEST [[
+---@generic V
+---@return fun(x: V):V
+local function f(x) end
+
+local v1 = f()
+local <?<!v2!>?> = v1(<!{}!>)
+]]
+
+TEST [[
+---@generic V
+---@param x V[]
+---@return V
+local function f(x) end
+
+---@class A
+local <!a!>
+
+---@type A[]
+local b
+
+local <?<!c!>?> = f(b)
+]]
+
+TEST [[
+---@generic V
+---@param x table<number, V>
+---@return V
+local function f(x) end
+
+---@class A
+local <!a!>
+
+---@type table<number, A>
+local b
+
+local <?<!c!>?> = f(b)
+]]
+
+TEST [[
+---@generic V
+---@param x V[]
+---@return V
+local function f(x) end
+
+---@class A
+local <!a!>
+
+---@type table<number, A>
+local b
+
+local <?<!c!>?> = f(b)
+]]
+
+TEST [[
+---@generic V
+---@param x table<number, V>
+---@return V
+local function f(x) end
+
+---@class A
+local <!a!>
+
+---@type A[]
+local b
+
+local <?<!c!>?> = f(b)
+]]
+
+TEST [[
+---@generic K
+---@param x table<K, number>
+---@return K
+local function f(x) end
+
+---@class A
+local <!a!>
+
+---@type table<A, number>
+local b
+
+local <?<!c!>?> = f(b)
+]]
+
+TEST [[
+---@generic V
+---@return fun(t: V[]):V
+local function f() end
+
+---@class A
+local <!a!>
+
+---@type A[]
+local b
+
+local f2 = f()
+
+local <?<!c!>?> = f2(b)
+]]
+
+TEST [[
+---@generic T, V
+---@param t T
+---@return fun(t: V[]):V
+---@return T
+local function f(t) end
+
+---@class A
+local <!a!>
+
+---@type A[]
+local b
+
+local f2, c = f(b)
+
+local <?<!d!>?> = f2(c)
+]]
+
+TEST [[
+---@class C
+local <!v1!>
+
+---@generic V, T
+---@param t T
+---@return fun(t: V): V
+---@return T
+local function iterator(t) end
+
+for <!v!> in iterator(<!v1!>) do
+ print(<?v?>)
+end
+]]
+
+TEST [[
+---@class C
+local <!v!>
+
+---@type C
+local <!v1!>
+
+---@generic V, T
+---@param t T
+---@return fun(t: V): V
+---@return T
+local function iterator(t) end
+
+for <!v!> in iterator(<!v1!>) do
+ print(<?v?>)
+end
+]]
+
+TEST [[
+---@class C
+local <!v!>
+
+---@type C[]
+local v1
+
+---@generic V, T
+---@param t T
+---@return fun(t: V[]): V
+---@return T
+local function iterator(t) end
+
+for <!v!> in iterator(v1) do
+ print(<?v?>)
+end
+]]
+
+TEST [[
---@class Foo
local Foo = {}
function Foo:<!bar1!>() end
---@type table<number, Foo>
local v1
-local ipairs = ipairs
+
+---@generic T: table, V
+---@param t T
+---@return fun(table: V[], i?: integer):integer, V
+---@return T
+---@return integer i
+local function ipairs(t) end
+
for i, v in ipairs(v1) do
print(v.<?bar1?>)
end
@@ -318,6 +570,35 @@ function Foo:<!bar1!>() end
---@type table<Foo, Foo>
local v1
+
+---@generic T: table, K, V
+---@param t T
+---@return fun(table: table<K, V>, index: K):K, V
+---@return T
+---@return nil
+local function pairs(t) end
+
+for k, v in pairs(v1) do
+ print(k.bar1)
+ print(v.<?bar1?>)
+end
+]]
+
+TEST [[
+---@class Foo
+local Foo = {}
+function Foo:<!bar1!>() end
+
+---@type table<Foo, Foo>
+local v1
+
+---@generic T: table, K, V
+---@param t T
+---@return fun(table: table<K, V>, index: K):K, V
+---@return T
+---@return nil
+local function pairs(t) end
+
for k, v in pairs(v1) do
print(k.<?bar1?>)
print(v.bar1)
@@ -329,6 +610,13 @@ TEST [[
local Foo = {}
function Foo:<!bar1!>() end
+---@generic T: table, V
+---@param t T
+---@return fun(table: V[], i?: integer):integer, V
+---@return T
+---@return integer i
+local function ipairs(t) end
+
---@type table<number, table<number, Foo>>
local v1
for i, v in ipairs(v1) do