Skip to content

Commit f8551a9

Browse files
committed
setlocal can be marked by ---@type
1 parent b390ad6 commit f8551a9

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

script/parser/luadoc.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@ local function bindDocsBetween(sources, binded, bindSources, start, finish)
13901390
if src.start >= start then
13911391
if src.type == 'local'
13921392
or src.type == 'self'
1393+
or src.type == 'setlocal'
13931394
or src.type == 'setglobal'
13941395
or src.type == 'tablefield'
13951396
or src.type == 'tableindex'

script/vm/compiler.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,14 @@ local compilerSwitch = util.switch()
976976
local runner = vm.createRunner(source)
977977
runner:launch(function (src, node)
978978
if src.type == 'setlocal' then
979+
if src.bindDocs then
980+
for _, doc in ipairs(src.bindDocs) do
981+
if doc.type == 'doc.type' then
982+
vm.setNode(src, vm.compileNode(doc), true)
983+
return
984+
end
985+
end
986+
end
979987
if src.value and guide.isLiteral(src.value) then
980988
if src.value.type == 'table' then
981989
vm.setNode(src, vm.createNode(src.value), true)
@@ -1260,6 +1268,9 @@ local compilerSwitch = util.switch()
12601268
local uri = guide.getUri(source)
12611269
vm.setNode(source, source)
12621270
local global = globalMgr.getGlobal('type', source.node[1])
1271+
if not global then
1272+
return
1273+
end
12631274
for _, set in ipairs(global:getSets(uri)) do
12641275
if set.type == 'doc.class' then
12651276
if set.extends then

test/type_inference/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,3 +2056,10 @@ local iter
20562056
for <?x?> in iter do
20572057
end
20582058
]]
2059+
2060+
TEST 'integer' [[
2061+
local x
2062+
2063+
---@type integer
2064+
<?x?> = XXX
2065+
]]

0 commit comments

Comments
 (0)