Skip to content

Commit 6321117

Browse files
committed
support @type for return
#2144
1 parent c3c73ef commit 6321117

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

script/parser/luadoc.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ local function bindDocsBetween(sources, binded, start, finish)
18221822
or src.type == 'setindex'
18231823
or src.type == 'setmethod'
18241824
or src.type == 'function'
1825-
or src.type == 'table'
1825+
or src.type == 'return'
18261826
or src.type == '...' then
18271827
if bindDoc(src, binded) then
18281828
ok = true
@@ -1934,7 +1934,7 @@ local bindDocAccept = {
19341934
'local' , 'setlocal' , 'setglobal',
19351935
'setfield' , 'setmethod' , 'setindex' ,
19361936
'tablefield', 'tableindex', 'self' ,
1937-
'function' , 'table' , '...' ,
1937+
'function' , 'return' , '...' ,
19381938
}
19391939

19401940
local function bindDocs(state)

script/vm/compiler.lua

+5
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,11 @@ function vm.selectNode(list, index)
766766
if not exp then
767767
return vm.createNode(vm.declareGlobal('type', 'nil')), nil
768768
end
769+
770+
if vm.bindDocs(list) then
771+
return vm.compileNode(list), exp
772+
end
773+
769774
---@type vm.node?
770775
local result
771776
if exp.type == 'call' then

test/type_inference/init.lua

+11
Original file line numberDiff line numberDiff line change
@@ -4314,10 +4314,21 @@ repeat
43144314
until <?x?>
43154315
]]
43164316

4317+
-- #2144
43174318
TEST 'A' [=[
43184319
local function f()
43194320
return {} --[[@as A]]
43204321
end
43214322
43224323
local <?x?> = f()
43234324
]=]
4325+
4326+
TEST 'A' [=[
4327+
local function f()
4328+
---@type A
4329+
return {}
4330+
end
4331+
4332+
local <?x?> = f()
4333+
]=]
4334+
--

0 commit comments

Comments
 (0)