summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-04-17 18:29:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-04-17 18:29:12 +0800
commit9f97b95a71e33d0f63b482fe7d2142dc4dda0716 (patch)
tree4c04398ce2dbeeda50a5af177773302b80b04f07
parent968aca97f67897583f9c5cec02b5901eeef2c86b (diff)
downloadlua-language-server-9f97b95a71e33d0f63b482fe7d2142dc4dda0716.zip
修正 `discard-returns` 对条件的误报
-rw-r--r--script/core/diagnostics/discard-returns.lua3
-rw-r--r--test/diagnostics/discard-returns.lua10
2 files changed, 13 insertions, 0 deletions
diff --git a/script/core/diagnostics/discard-returns.lua b/script/core/diagnostics/discard-returns.lua
index 9e573596..37d36214 100644
--- a/script/core/diagnostics/discard-returns.lua
+++ b/script/core/diagnostics/discard-returns.lua
@@ -15,6 +15,9 @@ return function (uri, callback)
if not guide.isBlockType(source.parent) then
return
end
+ if source.parent.filter == source then
+ return
+ end
await.delay()
if vm.isNoDiscard(source.node, true) then
callback {
diff --git a/test/diagnostics/discard-returns.lua b/test/diagnostics/discard-returns.lua
index 5acd6146..16ac8245 100644
--- a/test/diagnostics/discard-returns.lua
+++ b/test/diagnostics/discard-returns.lua
@@ -261,3 +261,13 @@ local t = {10, 20, 30}
for element in list_iter(t) do
end
]]
+
+TEST [[
+---@nodiscard
+local function f()
+ return 1
+end
+
+if f() then
+end
+]]