LuaLS / LuaLS/lua-language-server

Defining optional globals doesn't trigger nil check warning

Đang mở
#2,450 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

I have some code that runs in different environments that have different global variables available.

For example, environment1 may have a global table C_GameRules available with a function in it. environment2 does not have the global available.

I'm trying to write a meta file that makes this optional nature of this global available:

---@meta

---@type table?
C_GameRules = nil

---@return boolean
function C_GameRules.IsHardcoreActive() end

I've also tried to define a class, no change in behavior

Actual Behaviour

C_GameRules.IsHardcoreActive() does not trigger a need-nil-check warning, but the type of C_GameRules gets shown as table?

Reproduction steps

see above

Additional Notes

i don't want the inner field as nilable, environment 1 has "C_GameRules" as global available and the function is guaranteed to be in there, environment 2 has the global set to nil

Log File

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện báo cáo trong Visual Studio Code Extension bằng cách sử dụng khai báo tệp meta Lua được示 và kiểm tra các chẩn đoán kiểm tra kiểu cho C_GameRules.IsHardcoreActive(). Hoàn thành khi một phần tử global tùy chọn tạo ra cảnh báo kiểm tra nil, trong khi hàm bên trong của nó vẫn không thể 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
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
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.