diff options
Diffstat (limited to 'test/diagnostics/missing-return.lua')
-rw-r--r-- | test/diagnostics/missing-return.lua | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/test/diagnostics/missing-return.lua b/test/diagnostics/missing-return.lua index 9e5a99c9..b8c1e7d3 100644 --- a/test/diagnostics/missing-return.lua +++ b/test/diagnostics/missing-return.lua @@ -15,3 +15,144 @@ TEST [[ local function f() end ]] + +TEST [[ +---@return number +function F() + X = 1<!!> +end +]] +TEST [[ +local A +---@return number +function F() + if A then + return 1 + end<!!> +end +]] + +TEST [[ +local A, B +---@return number +function F() + if A then + return 1 + elseif B then + return 2 + end<!!> +end +]] + +TEST [[ +local A, B +---@return number +function F() + if A then + return 1 + elseif B then + return 2 + else + return 3 + end +end +]] + +TEST [[ +local A, B +---@return number +function F() + if A then + elseif B then + return 2 + else + return 3 + end<!!> +end +]] + +TEST [[ +---@return any +function F() + X = 1 +end +]] + +TEST [[ +---@return any, number +function F() + X = 1<!!> +end +]] + +TEST [[ +---@return number, any +function F() + X = 1<!!> +end +]] + +TEST [[ +---@return any, any +function F() + X = 1 +end +]] + +TEST [[ +local A +---@return number +function F() + for _ = 1, 10 do + if A then + return 1 + end + end + error('should not be here') +end +]] + +TEST [[ +local A +---@return number +function F() + while true do + if A then + return 1 + end + end +end +]] + +TEST [[ +local A +---@return number +function F() + while A do + if A then + return 1 + end + end<!!> +end +]] + +TEST [[ +local A +---@return number +function F() + while A do + if A then + return 1 + else + return 2 + end + end +end +]] + +TEST [[ +---@return number? +function F() + +end +]] |