File tree Expand file tree Collapse file tree 6 files changed +64
-57
lines changed
Expand file tree Collapse file tree 6 files changed +64
-57
lines changed Original file line number Diff line number Diff line change @@ -1303,16 +1303,13 @@ local compilerSwitch = util.switch()
13031303 end )
13041304 : case ' setglobal'
13051305 : call (function (source )
1306+ if bindDocs (source ) then
1307+ return
1308+ end
13061309 if source .node [1 ] ~= ' _ENV' then
13071310 return
13081311 end
1309- local key = guide .getKeyName (source )
1310- vm .compileByParentNode (source .node , key , function (src )
1311- if src .type == ' doc.type.field'
1312- or src .type == ' doc.field' then
1313- vm .setNode (source , vm .compileNode (src ))
1314- end
1315- end )
1312+ vm .setNode (source , vm .compileNode (source .value ))
13161313 end )
13171314 : case ' getglobal'
13181315 : call (function (source )
Original file line number Diff line number Diff line change @@ -521,10 +521,15 @@ function vm.compileByGlobal(source)
521521 if global .cate == ' variable' then
522522 vm .setNode (source , global )
523523 if guide .isAssign (source ) then
524- vm .setNode (source , vm .compileNode (source .value ))
524+ if source .value then
525+ vm .setNode (source , vm .compileNode (source .value ))
526+ end
525527 return
526528 end
527- vm .traceNode (source )
529+ local node = vm .traceNode (source )
530+ if node then
531+ vm .setNode (source , node , true )
532+ end
528533 return
529534 end
530535 local globalBase = vm .getGlobalBase (source )
Original file line number Diff line number Diff line change 214214
215215local lookIntoChild = util .switch ()
216216 : case ' getlocal'
217+ : case ' getglobal'
217218 --- @param tracer vm.tracer
218219 --- @param action parser.object
219220 --- @param topNode vm.node
@@ -466,7 +467,7 @@ local lookIntoChild = util.switch()
466467 and call .args then
467468 local getVar = call .args [1 ]
468469 if getVar
469- and tracer .assignMap [getVar ] then
470+ and tracer .getMap [getVar ] then
470471 for _ , ref in ipairs (action .ref ) do
471472 tracer :collectCare (ref )
472473 end
694695--- @param source parser.object
695696function mt :calcNode (source )
696697 if self .getMap [source ] then
697- local lastAssign = self :getLastAssign (0 , source .start )
698+ local lastAssign = self :getLastAssign (0 , source .finish )
698699 if not lastAssign then
699700 lastAssign = source .node
700701 end
Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ TEST [[
4646obj[#<?obj?>+1] = {}
4747]]
4848
49+ TEST [[
50+ self = {
51+ <!results!> = {}
52+ }
53+ self[self.<?results?>] = lbl
54+ ]]
55+
4956TEST [[
5057self = {
5158 results = {
Original file line number Diff line number Diff line change @@ -235,11 +235,8 @@ end)(<??>)
235235{' function (<!a: any!>, b: any)' }
236236
237237TEST [[
238- function X() end
239-
240- ---@param a number
241- function X(a) end
242-
238+ ---@overload fun()
239+ ---@overload fun(a:number)
243240---@param a number
244241---@param b number
245242function X(a, b) end
@@ -252,12 +249,9 @@ X(<??>)
252249' function X(<!a: number!>, b: number)' ,
253250}
254251
255- TEST [[
256- function X() end
257-
258- ---@param a number
259- function X(a) end
260-
252+ TEST [[ \
253+ ---@overload fun()
254+ ---@overload fun(a:number)
261255---@param a number
262256---@param b number
263257function X(a, b) end
@@ -270,11 +264,8 @@ X(<?1?>)
270264}
271265
272266TEST [[
273- function X() end
274-
275- ---@param a number
276- function X(a) end
277-
267+ ---@overload fun()
268+ ---@overload fun(a:number)
278269---@param a number
279270---@param b number
280271function X(a, b) end
@@ -286,11 +277,8 @@ X(1, <??>)
286277}
287278
288279TEST [[
289- function X() end
290-
291- ---@param a number
292- function X(a) end
293-
280+ ---@overload fun()
281+ ---@overload fun(a:number)
294282---@param a number
295283---@param b number
296284function X(a, b) end
Original file line number Diff line number Diff line change @@ -2893,10 +2893,7 @@ local <?x?> = echo(b)
28932893]]
28942894
28952895TEST ' boolean' [[
2896- ---@return boolean
2897- function f()
2898- end
2899-
2896+ ---@overload fun():boolean
29002897---@param x integer
29012898---@return number
29022899function f(x)
@@ -2906,10 +2903,7 @@ local <?x?> = f()
29062903]]
29072904
29082905TEST ' number' [[
2909- ---@return boolean
2910- function f()
2911- end
2912-
2906+ ---@overload fun():boolean
29132907---@param x integer
29142908---@return number
29152909function f(x)
@@ -2919,10 +2913,7 @@ local <?x?> = f(1)
29192913]]
29202914
29212915TEST ' boolean' [[
2922- ---@return boolean
2923- function f()
2924- end
2925-
2916+ ---@overload fun():boolean
29262917---@param x integer
29272918---@return number
29282919function f(x)
@@ -2936,10 +2927,7 @@ local <?x?> = f(r0())
29362927]]
29372928
29382929TEST ' number' [[
2939- ---@return boolean
2940- function f()
2941- end
2942-
2930+ ---@overload fun():boolean
29432931---@param x integer
29442932---@return number
29452933function f(x)
@@ -2953,10 +2941,7 @@ local <?x?> = f(r1())
29532941]]
29542942
29552943TEST ' boolean' [[
2956- ---@return boolean
2957- function f()
2958- end
2959-
2944+ ---@overload fun():boolean
29602945---@param x integer
29612946---@return number
29622947function f(x)
@@ -2969,10 +2954,7 @@ local <?x?> = f(r0())
29692954]]
29702955
29712956TEST ' number' [[
2972- ---@return boolean
2973- function f()
2974- end
2975-
2957+ ---@overload fun():boolean
29762958---@param x integer
29772959---@return number
29782960function f(x)
@@ -3430,7 +3412,7 @@ local mt = {}
34303412mt.<?x?> = nil
34313413]]
34323414
3433- TEST ' unknown ' [[
3415+ TEST ' nil ' [[
34343416mt = {}
34353417mt.<?x?> = nil
34363418]]
@@ -4148,3 +4130,30 @@ for _, <?x?> in ipairs(xs) do
41484130 x = f(x)
41494131end
41504132]]
4133+
4134+ TEST ' number' [[
4135+ ---@type number?
4136+ X = Y
4137+
4138+ if X then
4139+ print(<?X?>)
4140+ end
4141+ ]]
4142+
4143+ TEST ' number' [[
4144+ ---@type number|boolean
4145+ X = Y
4146+
4147+ if type(X) == 'number' then
4148+ print(<?X?>)
4149+ end
4150+ ]]
4151+
4152+ TEST ' boolean' [[
4153+ ---@type number|boolean
4154+ X = Y
4155+
4156+ if type(X) ~= 'number' then
4157+ print(<?X?>)
4158+ end
4159+ ]]
You can’t perform that action at this time.
0 commit comments