LuaLS / LuaLS/lua-language-server

Nil access check does not run

Open
#2,930 0 comments 1 reaction 0 assignees View on GitHub

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?

Other

Which OS are you using?

Linux

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

I have the minimal example

---@class A
---@field b fun(self: A): table?

---@return A[]
local function get_A()
  local l = {}
  for _ = 1, 10 do
    if math.random() > 0.5 then
      table.insert(l, { b = function(self) return { f = 4 } end })
    else
      table.insert(l, { b = function(self) print("hi" .. tostring(self)) end })
    end
  end
  return l
end

local as = get_A()
for i = 1, 10 do
  local a = as[i]
  if a:b().f > 3 then
    print("yo")
  end
end

The lsp should give me an error about a:b().f as a:b() could be nil.

Actual Behaviour

No warnings are shown.

Reproduction steps
  1. Copy the given code into an editor
  2. See that no errors are shown
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 running the minimal Lua example in an editor with lua-language-server and confirm that no diagnostic is emitted for a:b().f. Trace the diagnostics/syntax-checking path for chained calls and nullable return values. Done means the example reports that dereferencing a:b() may access a nil value, without introducing unrelated warnings.

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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.