LuaLS / LuaLS/lua-language-server
`need-check-nil` doesn't recognize nil check propagation
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?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
MacOS
What is the issue affecting?
Diagnostics/Syntax Checking
Expected Behaviour
Ideally, need-check-nil would infer a nil check has been completed if I've already done that nil check earlier as part of a larger check. Specifically, the statement if not (a and a.b) then will properly register as a nil check on a, but assigning the inner expression to a local var prevents LLS from detecting it as a nil check.
Actual Behaviour
LLS warns need-check-nil when a variable cannot possibly be nil, if the check was masked via another variable.
Reproduction steps
---@return table?
local function stuff()
return nil
end
local item = stuff()
local x = item and item.x
if not x then -- Works: `if not (item and item.x) then`
-- This includes case where `item` is `nil`
else
local subitem = item.key -- Error on `item` (need-check-nil)
end
Additional Notes
No response
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 bằng cách tái hiện chẩn đoán need-check-nil trong tiện ích mở rộng Visual Studio Code bằng ví dụ Lua trong issue, sau đó lần theo logic lan truyền nil-check của chẩn đoán. Được xem là hoàn tất khi ví dụ không còn cảnh báo về item.key, vì kiểm tra trước đó thông qua x đã loại trừ khả năng item là nil.
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, vscode
- 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
- 38/100