TEST [[ ---@class Foo ---@field field1 integer local mt = {} function mt:Constructor() self.field2 = 1 end function mt:method1() return 1 end function mt.method2() return 2 end ---@class Bar: Foo ---@field field4 integer local mt2 = {} ---@type Foo local v print(v.field1 + 1) print(v.field2 + 1) print(v. + 1) print(v:method1()) print(v.method2()) print(v:()) ---@type Bar local v2 print(v2.field1 + 1) print(v2.field2 + 1) print(v2. + 1) print(v2.field4 + 1) print(v2:method1()) print(v2.method2()) print(v2:()) local v3 = {} print(v3.abc) ---@class Bar2 local mt3 function mt3:method() return 1 end print(mt3:method()) ]] -- checkUndefinedField 通过type找到class TEST [[ ---@class Foo local Foo function Foo:method1() end ---@type Foo local v v:method1() v:() -- doc.class.name ]] -- checkUndefinedField 通过type找到class,涉及到 class 继承版 TEST [[ ---@class Foo local Foo function Foo:method1() end ---@class Bar: Foo local Bar function Bar:method3() end ---@type Bar local v v:method1() v:() -- doc.class.name v:method3() ]] -- checkUndefinedField 类名和类变量同名,类变量被直接使用 TEST [[ ---@class Foo local Foo function Foo:method1() end Foo:() -- doc.class Foo:() -- doc.class ]] -- checkUndefinedField 没有@class的不检测 TEST [[ local Foo function Foo:method1() return Foo:method2() -- table end ]] -- checkUndefinedField 类名和类变量不同名,类变量被直接使用、使用self TEST [[ ---@class Foo local mt function mt:method1() mt.() -- doc.class self:method1() return self.() -- doc.class.name end ]] -- checkUndefinedField 当会推导成多个class类型时 TEST [[ ---@class Foo local mt function mt:method1() end ---@class Bar local mt2 function mt2:method2() end ---@type Foo local v ---@type Bar local v2 v2 = v v2:method1() v2:() ]] TEST [[ ---@type table T1 = {} print(T1.f1) ---@type tablelib T2 = {} print(T2.) ]] TEST [[ ---@type string|table local n print(n.x) ]] TEST [[ ---@type 'x' local t local n = t:upper() ]] TEST [[ ---@alias A 'x' ---@type A local t local n = t:upper() ]]