LuaLS / LuaLS/lua-language-server
table newindex shows invalid `need check for nil` warning if key is `false`
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 442
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
### How are you using the lua-language-server?
NeoVim
### Which OS are you using?
Windows
### What is the issue affecting?
Type Checking
### Expected Behaviour
`t[key] = {}` should throw no warning if key is not nil.
### Actual Behaviour
`t[key] = {}` throws an invalid warning if key is false but not nil.
### Reproduction steps
```lua
local CACHE = {}
CACHE[false] = {} -- ok
local key = false
CACHE[key] = {} -- should be ok as well, but throws invalid warning
```
### Additional Notes
This happened to me in a more complex method where I ensured a key is not nil, by redefining the parameter:
```lua
function apicall(input)
local key = input or false
-- more stuff...
cache[key] = {}
return cache[key]
end
```
I'd like to note an annoyance when it comes to casting, the following casts all throw warnings, even if explicitly casting the variable, requiring me to invent a new variable (or forcing me disable redefining local):
```lua
---@param input string?
function apicall(input)
-- this cast does nothing and also throws no warning
---@cast input +false
-- this cast warns that it can't cast string? to string|false
---@cast input string|false
-- this is what I do, it just throws an info warning, which I've disabled:
---@type string | false
local input = input or false
end
```
### Log File
_No response_
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với bản tái hiện bằng Lua trong issue và lần theo đường đi của việc kiểm tra kiểu cho các thao tác table newindex khi khóa là false thay vì nil. Đồng thời xem xét các ví dụ cast được báo cáo, sau đó xác minh rằng các khóa hợp lệ có giá trị false không còn tạo ra cảnh báo, trong khi các khóa thực sự nil vẫn tạo ra cảnh báo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- lua
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100