TEST [[ ---@class ---@class B : ]] TEST [[ ---@class ---@type B| ]] TEST [[ ---@class Class local ?> ---@type Class local x ]] TEST [[ ---@class Class local ---@type Class local ?> ]] TEST [[ ---@class A local mt = {} function mt:() end ---@type A local obj obj:() ]] TEST [[ ---@class A local = {} function mt:cast() end ---@type A local :cast() ]] TEST [[ ---@type A local ?> ---@class A local ]] 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 [[ ---@overload ---@param x number ---@param y boolean ---@param z string function (x, y, z) end print() ]] TEST [[ local function f() return 1 end ---@class Class local ---@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 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 [[ ---@class Cat local ---hahaha ---@class Dog local m2 ---@type Cat local ?> ]] TEST [[ ---@class Cat local --hahaha ---@class Dog local m2 ---@type Cat local ?> ]] TEST [[ ---@class Cat local ---hahaha ---@class Dog local m2 ---@type Cat local ?> ]] TEST [[ ---@return local function f() end local ?> = f() ]] TEST [[ ---@generic T ---@param p T ---@return T local function f(p) end local local ?> = f() ]] 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 ---@type A[] local b local ?> = b[1] ]] TEST [[ ---@class A local ---@type table local b local ?> = b[1] ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@type table local v1 print(v1[1].) ]] TEST [[ ---@class Foo local Foo = {} function Foo:() end ---@class Foo2 local Foo2 = {} function Foo2:bar1() end ---@type Foo2 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 ---@type A[] local b local ?> = f(b) ]] TEST [[ ---@generic V ---@param x table ---@return V local function f(x) end ---@class A local ---@type table local b local ?> = f(b) ]] TEST [[ ---@generic V ---@param x V[] ---@return V local function f(x) end ---@class A local ---@type table local b local ?> = f(b) ]] TEST [[ ---@generic V ---@param x table ---@return V local function f(x) end ---@class A local ---@type A[] local b local ?> = f(b) ]] TEST [[ ---@generic K ---@param x table ---@return K local function f(x) end ---@class A local ---@type table local b local ?> = f(b) ]] TEST [[ ---@generic V ---@return fun(t: V[]):V local function f() end ---@class A local ---@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 ---@type A[] local b local f2, c = f(b) local ?> = f2(c) ]] TEST [[ ---@class C local ---@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 [[ ---@class C local ---@type C local ---@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 [[ ---@class C local ---@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 Foo local Foo = {} function Foo:() end ---@type table local v1 ---@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.) 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: V[], 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 ? boolean local t print(t[]) ]] TEST [[ ---@type { } local t print(t[]) ]] TEST [[ ---@class A ---@field ? boolean local t print(t.) ]] TEST [[ ---@type { } local t print(t.) ]] TEST [[ ---@class A local t.f = function (self) end ]]