LuaLS / lua-language-server

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

`need-check-nil` for `self` #1271

Closed berkcebi closed 2 years ago

berkcebi commented 2 years ago

Hey there, I use the language server VS Code extension for my Playdate project and it's been super helpful — thanks for your great work. 🙌

Since the latest release, I noticed that all the self calls I make are now flagged as Lua Diagnostics (need-check-nil). I'm not familiar with the internals of this diagnostic so I'm not sure if this is intended or not. Here's a sample:

class("Adventurer", { troops = {} }).extends()

function Adventurer:addTroop(troop)
    table.insert(self.troops, troop)
end

Here the self.troops call in the addTroop function now gets flagged as Lua Diagnostics (need-check-nil). (Playdate's class implementation can be found in their SDK.)

Screenshots

Screen Shot 2022-07-02 at 10 53 53 AM

Environment

berkcebi commented 2 years ago

In the sample I provided above, I realized adding Adventurer = {} above the class call solves the problem.