LuaLS / LuaLS/lua-language-server

string.unpack vararg returns

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

Chưa có ai nhận issue này.

enhancement
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?

Linux

What is the issue affecting?

Annotations, Type Checking, Completion

Expected Behaviour

The current string.unpack annotations (for the returns) are as following:

---@param fmt  string
---@param s    string
---@param pos? integer
---@return any ...
---@return integer offset
---@nodiscard
function string.unpack(fmt, s, pos) end

The function will indeed return any number of any returns followed by a single integer return for the new offset. As such you would expect that in the following example code, all of the returns are any except the last return be integer:

local a, b, c, d, offset = string.unpack('I2I2I2I2', "some binary data")
Actual Behaviour

Instead of the a, b, c, d being typed as any and offset being typed as integer, we instead see that a is typed as any, b is typed as integer, and c, d, offset are typed as nil.

This happen because it is not supported for a function to return a vararg followed by any return; it is always that vararg returns are the last return. Because of that, only the first return is typed as any and from there the second @return takes.

Reproduction steps
  1. Copy the example code.
  2. Hover over each return variable to notice the type.
Additional Notes

No response

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

Bắt đầu với chú thích string.unpack và tái hiện vấn đề trong extension Visual Studio Code bằng cách di chuột qua từng biến được trả về. Theo dõi cách trình kiểm tra kiểu xử lý một vararg theo sau bởi giá trị trả về offset. Hoàn tất khi các giá trị unpack được định kiểu là any và offset cuối cùng được định kiểu là integer.

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

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.