TEST [[ ---@class ---@class B : ]] TEST [[ ---@class ---@type B| ]] TEST [[ ---@class Class local ?> ---@type Class local x ]] TEST [[ ---@class Class local t ---@type Class local ?> ]] TEST [[ ---@class A local mt = {} function mt:() end ---@type A local obj obj:() ]] TEST [[ ---@class A ---@field x number ---@class B: A ---@field boolean ---@type B local t t. ]] TEST [[ ---@class A ---@field number ---@class B: A ---@type B local t t. ]] TEST [[ ---@class A local A function A:x() end ---@class B: A local B ---@type B local t local !> = t.x ]] TEST [[ ---@class A local A ---@class B: A local B ---@type B local t local !> = t.x ]] TEST [[ ---@type A local obj obj:() ---@class A local mt function mt:() end ]] TEST [[ ---@type A local obj obj:() ---@class A local mt = {} function mt:() end ]] TEST [[ ---@alias A ---@type ]] TEST [[ ---@class ---@param a ]] TEST [[ ---@type local ?> ]] TEST [[ ---@param f function t(?>) end ]] TEST [[ ---@vararg function f() end ]] TEST [[ ---@param ... function f() end ]] TEST [[ ---@alias A ---@type A local !> ]] TEST [[ ---@class A: ---@type A local !> ]] TEST [[ ---@overload ---@param x number ---@param y boolean ---@param z string function (x, y, z) end print() ]] TEST [[ local function f() local x return x end ---@class Class local mt ---@type Class local ?> = f() ]] TEST [[ ---@class Class ---@field string ---@field id integer local mt = {} mt. ]] TEST [[ ---@alias string ---@type ]] TEST [[ ---@class X ---@field string ---@class Y:X ---@type Y local y y. ]] TEST [[ ---@class local unit!> function unit:pants() end ---@see ]] TEST [[ ---@class loli local unit function unit:() end ---@see loli# ]] TEST [[ ---@class AAAA ---@field a AAAA AAAA = {}; function AAAA:() end AAAA.a. ]] TEST [[ ---@return local function f() end local ?> = f() ]] TEST [[ ---@generic T ---@param p T ---@return T local function f(p) end local k = local ?> = f(k) ]] 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.) ]] TEST [[ ---@class A local t t. = 1 ---@type A[] local b local c = b[1] c. ]] TEST [[ ---@class A local t t. = 1 ---@type { [number]: A } local b local c = b[1] c. ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@type { [number]: Foo } local v1 print(v1[1].) ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@class Foo2 local Foo2 = {} function Foo2:bar1() end ---@type { [number]: Foo } local v1 print(v1[1].) ]] --TODO 得扩展 simple 的信息才能识别这种情况了 --TEST [[ -----@class Foo --local Foo = {} --function Foo:bar1() end -- -----@class Foo2 --local Foo2 = {} --function Foo2:() end -- -----@type Foo2 --local v1 --print(v1.) --]] TEST [[ ---@type fun(): local f local ?> = f() ]] TEST [[ ---@generic T ---@type fun(x: T):T local f local ?> = f() ]] TEST [[ ---@generic T ---@param x T ---@return fun():T local function f(x) end local v1 = f() local ?> = v1() ]] TEST [[ ---@generic T ---@type fun(x: T):fun():T local f local v1 = f() local ?> = v1() ]] TEST [[ ---@generic V ---@return fun(x: V):V local function f(x) end local v1 = f() local ?> = v1() ]] TEST [[ ---@generic V ---@param x V[] ---@return V local function f(x) end ---@class A local a a. = 1 ---@type A[] local b local c = f(b) c. ]] TEST [[ ---@generic V ---@param x { [number]: V } ---@return V local function f(x) end ---@class A local a a. = 1 ---@type { [number]: A } local b local c = f(b) c. ]] TEST [[ ---@generic V ---@param x { [number]: V } ---@return V local function f(x) end ---@class A local a a. = 1 ---@type { [integer]: A } local b local c = f(b) c. ]] TEST [[ ---@generic V ---@param x { [integer]: V } ---@return V local function f(x) end ---@class A local a a.x = 1 ---@type { [number]: A } local b local c = f(b) c. ]] TEST [[ ---@generic V ---@param x { [number]: V } ---@return V local function f(x) end ---@class A local a a. = 1 ---@type A[] local b local c = f(b) c. ]] TEST [[ ---@generic K ---@param x { [K]: number } ---@return K local function f(x) end ---@class A local a a. = 1 ---@type { [A]: number } local b local c = f(b) c. ]] TEST [[ ---@generic K ---@param x { [K]: A } ---@return K local function f(x) end ---@class A local a a.x = 1 ---@type A[] local b local c = f(b) c. ]] TEST [[ ---@generic K ---@param x { [K]: number } ---@return K local function f(x) end ---@class A local a a. = 1 ---@type { [A]: integer } local b local c = f(b) c. ]] TEST [[ ---@generic K ---@param x { [K]: integer } ---@return K local function f(x) end ---@class A local a a.x = 1 ---@type { [A]: number } local b local c = f(b) c. ]] TEST [[ ---@generic V ---@return fun(t: V[]):V local function f() end ---@type A[] local b local f2 = f() local ?> = 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 a. = 1 ---@type A[] local b local f2, c = f(b) local d = f2(c) d. ]] TEST [[ ---@generic V, T ---@param t T ---@return fun(t: V): V ---@return T local function iterator(t) end for in iterator() do print() end ]] TEST [[ ---@alias C ---@type C[] local v1 ---@generic V, T ---@param t T ---@return fun(t: V[]): V ---@return T local function iterator(t) end for in iterator(v1) do print() end ]] TEST [[ ---@class TT: { } ---@type TT local t ---@class A: print(t.) ]] TEST [[ ---@alias TT { } ---@type TT local t ---@class A: print(t.) ]] TEST [[ ---@class TT: { [number]: V } ---@type TT<> local v1 ---@generic V, T ---@param t T ---@return fun(t: { [number]: V }): V ---@return T local function iterator(t) end for in iterator(v1) do print() end ]] TEST [[ ---@class TT: { [K]: V } ---@type TT> local v1 ---@generic V, T ---@param t T ---@return fun(t: { [number]: V }): V ---@return T local function iterator(t) end for in iterator(v1) do print() end ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@type { [number]: Foo } local v1 ---@generic T: table, V ---@param t T ---@return fun(table: { [number]: V }, i?: integer):integer, V ---@return T ---@return integer i local function ipairs(t) end for i, v in ipairs(v1) do print(v.) end ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@type table local v1 ---@generic T: table, V ---@param t T ---@return fun(table: { [number]: V }, i?: integer):integer, V ---@return T ---@return integer i local function ipairs(t) end for i, v in ipairs(v1) do print(v.) end ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@type table local v1 ---@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 for k, v in pairs(v1) do print(k.bar1) print(v.) end ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@type table local v1 ---@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 for k, v in pairs(v1) do print(k.) print(v.bar1) end ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@generic T: table, V ---@param t T ---@return fun(table: table, i?: integer):integer, V ---@return T ---@return integer i local function ipairs(t) end ---@type table> local v1 for i, v in ipairs(v1) do local v2 = v[1] print(v2.) end ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@type table> local v1 print(v1[1][1].) ]] TEST [[ ---@class X ---@class Y ---@field string ---@class Z:X, Y ---@type Z local z z. ]] TEST [[ ---@type { , y: number } local t print(t.) ]] TEST [[ ---@class A ---@field [1]? local t local !> = t[1] ]] TEST [[ ---@type { [1]?: } local t local !> = t[1] ]] TEST [[ ---@class A ---@field ? local t print(t.) ]] TEST [[ ---@type { } local t print(t.) ]] TEST [[ ---@class A local t.f = function (self) end ]]