LuaLS / LuaLS/lua-language-server

Narrowing Types Issue

Open
#2,189 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour
---@param param1 true | nil
---@param param2 false | nil
local function test(param1, param2)
	if param1 == nil and param2 == nil then
		local var3 = param1
		local var4 = param2
	elseif param1 ~= nil and param2 == nil then
		local var5 = param1
		local var6 = param2
	elseif param1 == nil and param2 ~= nil then
		local var7 = param1
		local var8 = param2
	else
		local var9 = param1
		local var10 = param2
	end
end

In this function the vars should have the following types:
var3: nil
var4: nil
var5: true
var6: nil
var7: nil
var8: false
var9: true
var10: false

Actual Behaviour

The actual values are:
var3: nil (correct)
var4: nil (correct)
var5: true (correct)
var6: nil (correct)
var7: nil (correct)
var8: unknown (incorrect)
var9: true | nil (incorrect)
var10: false | nil (incorrect)

Reproduction steps
  1. Copy Code
  2. See Issue
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

Start by reproducing the Lua snippet in the Visual Studio Code extension on Windows and trace the type-checking behavior for the final two branches. Done means the inferred types match the report: var8 is false, var9 is true, and var10 is false, with the earlier variables retaining their listed types.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.