/
self.lua
106 lines (76 loc) · 1.89 KB
/
self.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---@type number
local aNumber
---@type string
local aString
---@class SelfA
---@field a string
local SelfA = {}
---@return self
function SelfA:colonMethod()
---@type self
local selfTypedVar = self
---@type SelfA
local someSelfA
someSelfA = self
self = someSelfA -- Expect error
selfTypedVar = someSelfA -- Expect error
aNumber = self -- Expect error
aNumber = self.a -- Expect error
aString = self.a
return self
end
---@type number
self = 1
---@return self
function SelfA.dotMethod()
---@type self
local selfTypedVar = self -- Expect error
---@type SelfA
local someSelfA
someSelfA = self
self = someSelfA -- Expect error
selfTypedVar = someSelfA -- Expect error
aNumber = self -- Expect error
aNumber = self.a -- Expect error
aString = self.a
return self
end
---@return self
SelfA.lambdaMethod = function()
---@type self
local selfTypedVar = self
---@type SelfA
local someSelfA
someSelfA = self
self = someSelfA -- Expect error
selfTypedVar = someSelfA -- Expect error
aNumber = self -- Expect error
aNumber = self.a -- Expect error
aString = self.a
return self
end
---@type SelfA
local selfA
---@class SelfB : SelfA
---@field bb string
local SelfB = {}
---@type SelfB
local selfB
selfB = SelfB:colonMethod()
selfB = SelfB:dotMethod()
selfB = SelfB:lambdaMethod()
selfA = SelfB:colonMethod()
selfA = SelfB:dotMethod()
selfA = SelfB:lambdaMethod()
selfB = SelfA:colonMethod() -- Expect error
selfB = SelfA:dotMethod() -- Expect error
selfB = SelfA:lambdaMethod() -- Expect error
selfB = selfB:colonMethod()
selfB = selfB:dotMethod()
selfB = selfB:lambdaMethod()
selfA = selfB:colonMethod()
selfA = selfB:dotMethod()
selfA = selfB:lambdaMethod()
selfB = selfA:colonMethod() -- Expect error
selfB = selfA:dotMethod() -- Expect error
selfB = selfA:lambdaMethod() -- Expect error