diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | meta/template/basic.lua | 2 | ||||
-rw-r--r-- | meta/template/table.lua | 2 | ||||
-rw-r--r-- | meta/template/utf8.lua | 4 | ||||
-rw-r--r-- | script/vm/compiler.lua | 13 | ||||
-rw-r--r-- | script/vm/function.lua | 9 | ||||
-rw-r--r-- | test/type_inference/init.lua | 28 |
7 files changed, 50 insertions, 9 deletions
diff --git a/changelog.md b/changelog.md index 5c99dd5e..20b73e9f 100644 --- a/changelog.md +++ b/changelog.md @@ -33,6 +33,7 @@ ---@type { x: fun():boolean; y: boolean } ---@type { (x: fun():boolean), y: boolean } ``` +* `CHG` supports `---@return boolean ...` * `CHG` improve experience for diagnostics and semantic-tokens * `FIX` diagnostics flash when opening a file * `FIX` sometimes workspace diagnostics are not triggered diff --git a/meta/template/basic.lua b/meta/template/basic.lua index 6a89fb01..7afbf273 100644 --- a/meta/template/basic.lua +++ b/meta/template/basic.lua @@ -284,6 +284,6 @@ function xpcall(f, msgh, arg1, ...) end ---@param list T[] ---@param i? integer ---@param j? integer ----@return T +---@return T ... ---@nodiscard function unpack(list, i, j) end diff --git a/meta/template/table.lua b/meta/template/table.lua index b0a386c3..1cb2f56f 100644 --- a/meta/template/table.lua +++ b/meta/template/table.lua @@ -61,7 +61,7 @@ function table.sort(list, comp) end ---@param list T[] ---@param i? integer ---@param j? integer ----@return T +---@return T ... ---@nodiscard function table.unpack(list, i, j) end diff --git a/meta/template/utf8.lua b/meta/template/utf8.lua index a00a3238..1797a5e8 100644 --- a/meta/template/utf8.lua +++ b/meta/template/utf8.lua @@ -33,7 +33,7 @@ function utf8.codes(s, lax) end ---@param i? integer ---@param j? integer ---@return integer code ----@return ... +---@return integer ... ---@nodiscard function utf8.codepoint(s, i, j) end ---#else @@ -42,7 +42,7 @@ function utf8.codepoint(s, i, j) end ---@param j? integer ---@param lax? boolean ---@return integer code ----@return ... +---@return integer ... ---@nodiscard function utf8.codepoint(s, i, j, lax) end ---#end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index e62f7843..00c8170c 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1519,9 +1519,16 @@ local compilerSwitch = util.switch() end end end - if lastReturn and not hasMarkDoc and lastReturn.types[1][1] == '...' then - hasMarkDoc = true - vm.setNode(source, vm.declareGlobal('type', 'unknown')) + 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)) + end end end local hasReturn diff --git a/script/vm/function.lua b/script/vm/function.lua index 9efcbd32..bdb70faf 100644 --- a/script/vm/function.lua +++ b/script/vm/function.lua @@ -113,8 +113,13 @@ function vm.countReturnsOfFunction(func, mark) end end end - if lastReturn and lastReturn.types[1][1] == '...' then - dmax = math.huge + 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 end if dmin and (not min or (dmin < min)) then min = dmin diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 8cf98da5..e86983b6 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3064,3 +3064,31 @@ local t local <?f?> = t.f ]] + +TEST 'boolean' [[ +---@param ... boolean +local function f(...) + local <?n?> = ... +end +]] + +TEST 'boolean' [[ +---@param ... boolean +local function f(...) + local _, <?n?> = ... +end +]] + +TEST 'boolean' [[ +---@return boolean ... +local function f() end + +local <?n?> = f() +]] + +TEST 'boolean' [[ +---@return boolean ... +local function f() end + +local _, <?n?> = f() +]] |