diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-04-16 17:07:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-16 17:07:22 +0800 |
commit | 86ca6317bcdaf54e3b504f393547da010bf11841 (patch) | |
tree | c60c8a2d8a90db7b2a023d9137f010f9308f2908 /test | |
parent | 0e44a7db4cb535ee79630876ea02bccf5e2693a1 (diff) | |
parent | ce938c864604155fc081dab017867e7e461c61cc (diff) | |
download | lua-language-server-86ca6317bcdaf54e3b504f393547da010bf11841.zip |
Merge pull request #2585 from clay-golem/fix/discard-returns-trigger
Detect discard-returns in all block types
Diffstat (limited to 'test')
-rw-r--r-- | test/diagnostics/discard-returns.lua | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/test/diagnostics/discard-returns.lua b/test/diagnostics/discard-returns.lua index 2e348390..5acd6146 100644 --- a/test/diagnostics/discard-returns.lua +++ b/test/diagnostics/discard-returns.lua @@ -15,3 +15,249 @@ end X = f() ]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +for i = 1, 2 do + <!f()!> +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +for i = 1, 2 do + local v = f() +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +while true do + <!f()!> + break +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +while true do + local v = f() + break +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +repeat + <!f()!> + break +until true +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +repeat + local v = f() + break +until true +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +for index, value in ipairs({}) do + <!f()!> +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +for index, value in ipairs({}) do + local v = f() +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +if 1 == 1 then + <!f()!> +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +if 1 == 1 then + local v = f() +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +if 1 == 1 then + local v = f() +else + <!f()!> +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +if 1 == 1 then + local v = f() +else + local v = f() +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +if 1 == 1 then + local v = f() +elseif 1 == 2 then + <!f()!> +else + local v = f() +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +if 1 == 1 then + local v = f() +elseif 1 == 2 then + local v = f() +else + local v = f() +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +local function bar(callback) +end + +bar(function () + <!f()!> +end) +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +local function bar(callback) +end + +bar(function () + local v = f() +end) +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +do + <!f()!> +end +]] + +TEST [[ +---@nodiscard +local function f() + return 1 +end + +do + local v = f() +end +]] + +TEST [[ +---@nodiscard +local function f() + return 2 +end + +for i = 1, f() do +end +]] + +TEST [[ +---@nodiscard +local function list_iter(t) + local i = 0 + local n = #t + return function () + i = i + 1 + if i <= n then return t[i] end + end +end + +local t = {10, 20, 30} +for element in list_iter(t) do +end +]] |