LuaLS / LuaLS/lua-language-server

Nil check for functions

Open
#2,523 0 comments 2 reactions 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?

NeoVim

### Which OS are you using?

Linux

### What is the issue affecting?

Type Checking, Diagnostics/Syntax Checking

### Expected Behaviour

```lua
---@class Type1
---@field maybe_fun? fun(a: integer)
---@field absolutely_nil nil

---@type Type1
local type {
maybe_fun = nil
absolutely_nil = nil
}

type.maybe_fun(5) -- ERROR "maybe_fun" is nil, add nil check
type.absolutely_nil() -- ERROR "absolutely_nil" is nil
```

### Actual Behaviour

```lua
---@class Type1
---@field maybe_fun? fun(a: integer)
---@field absolutely_nil nil

---@type Type1
local type {
maybe_fun = nil
absolutely_nil = nil
}
-- No error messages, luals does not complain at all
type.maybe_fun(5)
type.absolutely_nil()
```

### Reproduction steps

1. Run example

### 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

The issue names no source file or test; start by reproducing the Lua example in NeoVim on Linux and trace the type-checking and diagnostic entry point for calls through nil-typed fields. Done means diagnostics report both nil call cases shown, including the optional function and the field typed as nil.

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.