LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.38k stars 320 forks source link

Nil access check does not run #2930

Open opfromthestart opened 3 weeks ago

opfromthestart commented 3 weeks ago

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