Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions script/core/diagnostics/discard-returns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ return function (uri, callback)
end
---@async
guide.eachSourceType(state.ast, 'call', function (source)
local parent = source.parent
if parent.type ~= 'function'
and parent.type ~= 'main' then
if not guide.isBlockType(source.parent) then
return
end
await.delay()
Expand Down
246 changes: 246 additions & 0 deletions test/diagnostics/discard-returns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
]]