diff options
Diffstat (limited to 'test/diagnostics/missing-return.lua')
-rw-r--r-- | test/diagnostics/missing-return.lua | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/test/diagnostics/missing-return.lua b/test/diagnostics/missing-return.lua new file mode 100644 index 00000000..b8c1e7d3 --- /dev/null +++ b/test/diagnostics/missing-return.lua @@ -0,0 +1,158 @@ +TEST [[ +---@type fun():number +local function f() +<!!>end +]] + +TEST [[ +---@type fun():number? +local function f() +end +]] + +TEST [[ +---@type fun():... +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 +]] |