summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-28 19:28:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-28 19:28:54 +0800
commitdeac4582d38908c1281d4d5215b7b69ff8400dca (patch)
tree833da004bc6bd82dadb373bbc345224160ce0972
parent7e778b31476831864dff995ae3ae4e5f223c5726 (diff)
downloadlua-language-server-deac4582d38908c1281d4d5215b7b69ff8400dca.zip
parse `---@return ...` a `---@return ... unknown`
-rw-r--r--script/parser/luadoc.lua16
-rw-r--r--script/vm/compiler.lua18
-rw-r--r--script/vm/function.lua6
-rw-r--r--test/hover/init.lua10
-rw-r--r--test/type_inference/init.lua2
5 files changed, 27 insertions, 25 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index e71c6f18..c1a8d19c 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -452,6 +452,10 @@ local function parseTypeUnitFunction(parent)
name = returnName
return true
end
+ if returnName[1] == '...' then
+ name = returnName
+ return false
+ end
return false
end)
local rtn = parseType(typeUnit)
@@ -648,13 +652,16 @@ function parseTypeUnit(parent)
or parseCode(parent)
or parseInteger(parent)
or parseBoolean(parent)
- or parseDots('doc.type.name', parent)
or parseParen(parent)
if not result then
result = parseName('doc.type.name', parent)
+ or parseDots('doc.type.name', parent)
if not result then
return nil
end
+ if result[1] == '...' then
+ result[1] = 'unknown'
+ end
end
while true do
local newResult = parseTypeUnitSign(parent, result)
@@ -918,6 +925,10 @@ local docSwitch = util.switch()
returns = {},
}
while true do
+ local dots = parseDots('doc.return.name')
+ if dots then
+ Ci = Ci - 1
+ end
local docType = parseType(result)
if not docType then
break
@@ -929,7 +940,8 @@ local docSwitch = util.switch()
nextToken()
docType.optional = true
end
- docType.name = parseName('doc.return.name', docType)
+ docType.name = dots
+ or parseName('doc.return.name', docType)
or parseDots('doc.return.name', docType)
result.returns[#result.returns+1] = docType
if not checkToken('symbol', ',', 1) then
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index e7af1f0f..9a5eba7f 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1553,10 +1553,6 @@ local compilerSwitch = util.switch()
end
if lastReturn
and not hasMarkDoc then
- if lastReturn.types[1][1] == '...' then
- hasMarkDoc = true
- vm.setNode(source, vm.declareGlobal('type', 'unknown'))
- end
if lastReturn.name and lastReturn.name[1] == '...' then
hasMarkDoc = true
vm.setNode(source, vm.compileNode(lastReturn))
@@ -1618,13 +1614,6 @@ local compilerSwitch = util.switch()
if not node then
return
end
- for n in node:eachObject() do
- if n.type == 'global'
- and n.cate == 'type'
- and n.name == '...' then
- return
- end
- end
vm.setNode(source, node)
end
if vararg.type == 'varargs' then
@@ -1643,13 +1632,6 @@ local compilerSwitch = util.switch()
if not node then
return
end
- for n in node:eachObject() do
- if n.type == 'global'
- and n.cate == 'type'
- and n.name == '...' then
- return
- end
- end
vm.setNode(source, node)
end)
: case 'doc.type'
diff --git a/script/vm/function.lua b/script/vm/function.lua
index 8e3662e2..d94e7561 100644
--- a/script/vm/function.lua
+++ b/script/vm/function.lua
@@ -98,16 +98,14 @@ function vm.countReturnsOfFunction(func, mark)
n = n + 1
lastReturn = ret
dmax = n
- if not vm.compileNode(ret):isNullable() then
+ if (not ret.name or ret.name[1] ~= '...')
+ and not vm.compileNode(ret):isNullable() then
dmin = n
end
end
end
end
if lastReturn then
- if lastReturn.types[1][1] == '...' then
- dmax = math.huge
- end
if lastReturn.name and lastReturn.name[1] == '...' then
dmax = math.huge
end
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 9cdf2ed4..acb779bf 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -2042,6 +2042,16 @@ function f(...boolean)
]]
TEST [[
+---@param ... boolean
+---@return ...
+local function <?f?>(...) end
+]]
+[[
+function f(...boolean)
+ -> ...unknown
+]]
+
+TEST [[
---@type fun():x: number
local <?f?>
]]
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index a8ea4cf3..d56761c5 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -515,7 +515,7 @@ TEST 'fun(a: string, b: any, ...any)' [[
local <?x?>
]]
-TEST 'fun(a: string, b: any, c?: boolean, ...any):c, d?, ...' [[
+TEST 'fun(a: string, b: any, c?: boolean, ...any):c, d?, ...unknown' [[
---@type fun(a: string, b, c?: boolean, ...):c, d?, ...
local <?x?>
]]