Skip to content

Commit deac458

Browse files
committed
parse ---@return ... a ---@return ... unknown
1 parent 7e778b3 commit deac458

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

script/parser/luadoc.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ local function parseTypeUnitFunction(parent)
452452
name = returnName
453453
return true
454454
end
455+
if returnName[1] == '...' then
456+
name = returnName
457+
return false
458+
end
455459
return false
456460
end)
457461
local rtn = parseType(typeUnit)
@@ -648,13 +652,16 @@ function parseTypeUnit(parent)
648652
or parseCode(parent)
649653
or parseInteger(parent)
650654
or parseBoolean(parent)
651-
or parseDots('doc.type.name', parent)
652655
or parseParen(parent)
653656
if not result then
654657
result = parseName('doc.type.name', parent)
658+
or parseDots('doc.type.name', parent)
655659
if not result then
656660
return nil
657661
end
662+
if result[1] == '...' then
663+
result[1] = 'unknown'
664+
end
658665
end
659666
while true do
660667
local newResult = parseTypeUnitSign(parent, result)
@@ -918,6 +925,10 @@ local docSwitch = util.switch()
918925
returns = {},
919926
}
920927
while true do
928+
local dots = parseDots('doc.return.name')
929+
if dots then
930+
Ci = Ci - 1
931+
end
921932
local docType = parseType(result)
922933
if not docType then
923934
break
@@ -929,7 +940,8 @@ local docSwitch = util.switch()
929940
nextToken()
930941
docType.optional = true
931942
end
932-
docType.name = parseName('doc.return.name', docType)
943+
docType.name = dots
944+
or parseName('doc.return.name', docType)
933945
or parseDots('doc.return.name', docType)
934946
result.returns[#result.returns+1] = docType
935947
if not checkToken('symbol', ',', 1) then

script/vm/compiler.lua

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,10 +1553,6 @@ local compilerSwitch = util.switch()
15531553
end
15541554
if lastReturn
15551555
and not hasMarkDoc then
1556-
if lastReturn.types[1][1] == '...' then
1557-
hasMarkDoc = true
1558-
vm.setNode(source, vm.declareGlobal('type', 'unknown'))
1559-
end
15601556
if lastReturn.name and lastReturn.name[1] == '...' then
15611557
hasMarkDoc = true
15621558
vm.setNode(source, vm.compileNode(lastReturn))
@@ -1618,13 +1614,6 @@ local compilerSwitch = util.switch()
16181614
if not node then
16191615
return
16201616
end
1621-
for n in node:eachObject() do
1622-
if n.type == 'global'
1623-
and n.cate == 'type'
1624-
and n.name == '...' then
1625-
return
1626-
end
1627-
end
16281617
vm.setNode(source, node)
16291618
end
16301619
if vararg.type == 'varargs' then
@@ -1643,13 +1632,6 @@ local compilerSwitch = util.switch()
16431632
if not node then
16441633
return
16451634
end
1646-
for n in node:eachObject() do
1647-
if n.type == 'global'
1648-
and n.cate == 'type'
1649-
and n.name == '...' then
1650-
return
1651-
end
1652-
end
16531635
vm.setNode(source, node)
16541636
end)
16551637
: case 'doc.type'

script/vm/function.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,14 @@ function vm.countReturnsOfFunction(func, mark)
9898
n = n + 1
9999
lastReturn = ret
100100
dmax = n
101-
if not vm.compileNode(ret):isNullable() then
101+
if (not ret.name or ret.name[1] ~= '...')
102+
and not vm.compileNode(ret):isNullable() then
102103
dmin = n
103104
end
104105
end
105106
end
106107
end
107108
if lastReturn then
108-
if lastReturn.types[1][1] == '...' then
109-
dmax = math.huge
110-
end
111109
if lastReturn.name and lastReturn.name[1] == '...' then
112110
dmax = math.huge
113111
end

test/hover/init.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,16 @@ function f(...boolean)
20412041
-> ...number
20422042
]]
20432043

2044+
TEST [[
2045+
---@param ... boolean
2046+
---@return ...
2047+
local function <?f?>(...) end
2048+
]]
2049+
[[
2050+
function f(...boolean)
2051+
-> ...unknown
2052+
]]
2053+
20442054
TEST [[
20452055
---@type fun():x: number
20462056
local <?f?>

test/type_inference/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ TEST 'fun(a: string, b: any, ...any)' [[
515515
local <?x?>
516516
]]
517517

518-
TEST 'fun(a: string, b: any, c?: boolean, ...any):c, d?, ...' [[
518+
TEST 'fun(a: string, b: any, c?: boolean, ...any):c, d?, ...unknown' [[
519519
---@type fun(a: string, b, c?: boolean, ...):c, d?, ...
520520
local <?x?>
521521
]]

0 commit comments

Comments
 (0)