LuaLS / LuaLS/lua-language-server
Wrongly detects unreachable code
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Linux
What is the issue affecting?
Diagnostics/Syntax Checking, Hover
Expected Behaviour
Given the following code
local arr = {}
for k,v in pairs(arr) do
if k == 1 then
print("k == 1")
error("hi", k, v)
else
error("hi", k, v)
end
end
print("hello world")
print in the last line should not be marked as unreachable, since arr is empty and error is never called.
Actual Behaviour
print in the last line is marked as unreachable.
Reproduction steps
- Open New Tab in VSCode
- Paste code example from above
- if not set automatically, change language to lua
- see last line being greyed out
Additional Notes
No response
Log File
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic in the LuaLS Visual Studio Code extension using the provided snippet on Linux, then trace the unreachable-code analysis for the loop and its final print statement. Done means the final print is no longer marked unreachable when the loop iterates over an empty table.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100