LuaLS / LuaLS/lua-language-server
Generics in nested functions don't work for some annotations unless there are no arguments passed
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?
Annotations
Expected Behaviour
passing an argument should have no effect, and the types of nested functions should be resolved correctly
some examples:
---@generic T
---@param arg T
---@return fun(): fun(): T
local function POOL1(arg) return function() return function() return arg end end end -- implementing the function makes no difference for the typing
local func1 = POOL1(5.2) -- type is `fun(): fun(): number`
local func2 = func1(4) -- type should be `fun(): number`, instead it's `fun(): <T>` with an unresolved generic
---@class POOL2<T>: { EnumerateActive: fun():(T, fun():T)) }
---@type POOL2<number>
local headerPool = {}
local number, func = headerPool:EnumerateActive()
-- number type is `number`
-- func type should be `fun(): number`, instead it's `fun(): <T>` with an unresolved generic
---@alias POOL3<T> fun(arg: number): T, (fun():T)
---@type POOL3<number>
local getPool
local number, func = getPool(3)
-- number type is `number`
-- func type should be `fun(): number`, instead it's `fun(): <T>` with an unresolved generic
all 3 examples work fine if you don't pass any argument
Actual Behaviour
when an argument is passed to the outer function, the inner function doesn't have the generic resolved
if no arguments are passed (i.e. headerPool.EnumerateActive()), then they are resolved properly
the type of the argument makes no difference, and annotating the function as accepting an argument also makes no difference
interestingly, when hovering over the function itself, the tooltip does show the correctly resolved types
Reproduction steps
copy the provided snippets, and check which types the variables resolve to
Additional Notes
Tested on both VSCode and Jetbrains IDEs
The example is contrived, my real usecase is to annotate an object pool class, that allows you to acquire objects of a given (generic) type, and allows iterating over them.
I know this has worked in a past version, though I don't remember how long ago that was (several weeks or months most likely)
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 ba ví dụ chú thích Lua được cung cấp và kiểm tra cách các kiểu generic lồng nhau được phân giải khi hàm bên ngoài nhận một đối số. So sánh các kiểu được suy luận với các trường hợp không có đối số và các kết quả hover mong đợi. Được xem là hoàn tất khi cả ba ví dụ đều phân giải các hàm bên trong của chúng thành kiểu cụ thể, chẳng hạn như number, đồng thời giữ nguyên hành vi đúng hiện có.
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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 48/100