LuaLS / LuaLS/lua-language-server

Wrongly detects unreachable code

Open
#2,282 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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.

grafik

Reproduction steps
  1. Open New Tab in VSCode
  2. Paste code example from above
  3. if not set automatically, change language to lua
  4. see last line being greyed out
Additional Notes

No response

Log File

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.