Async flag lost when alias with type parameters (@alias Name<T> async fun) is used
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Reproduce with the issue's ---@alias Name<T> async fun(): T snippets and hover output. The async flag is likely dropped where generic alias types get substituted — start in script/vm/ (alias/global resolution) and script/compiler/ where function types are marked async, then check script/core/diagnostics/await-in-sync.lua for how the flag is read. Done means generic-parameterized async aliases report async on hover and trigger await-in-sync, verified via the repo's test harness under script/tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
When using alias generics where the alias is an async function, it should be marked with async when I give it a generic type.
```---@alias MyAsyncFunc<T> async fun(): T
---@type MyAsyncFunc<string>
local function my_function()
return "test"
end
my_function() -- on hover, it shows async
---@diagnostic enable: await-in-sync
local function async_context()
my_function() -- raises `await-in-sync` warning since the outer function is not marked as async
end
Actual Behaviour
When using alias generics like this, the async flag marked on those functions gets removed:
---@alias Name<T> async fun(): T
---@alias Name2<T> async fun(a: T)
---@alias Name3<T> async fun(a: T): T
Refer to the test cases below:
---@alias AsyncFuncT async fun(): any
---@alias AsyncGenericFuncT<T> async fun(): T
---@alias AnotherAsyncGenericFuncT<T> async fun(val: T)
---@alias DifferentAsyncFormat async fun<T>(val: T): T
---@class TestClass
---@field field AsyncFuncT
---@field generic_field AsyncGenericFuncT<string>
---@field another_generic AnotherAsyncGenericFuncT<integer>
---@field different DifferentAsyncFormat
---@type TestClass
local test_fields = {
field = function() end, --- correctly marks async
generic_field = function() -- the function is not tagged as async
return "hello" -- the return type is correctly tagged as string
end,
another_generic = function(num) -- the function is not tagged as async
print(num) -- the num is correctly tagged as integer
end,
different = function(x) -- correctly tags as async
return x
end,
}
---@type AsyncFuncT
local function test() end
test() -- correctly tags as async
---@type AsyncGenericFuncT<string>
local function test2()
return "hello" -- correctly tags the return type as string
end
test2() -- does not tag as async
---@type AnotherAsyncGenericFuncT<integer>
local function test3(num)
print(num) -- correctly tags as integer
end
test3(2) -- does not tag as async
---@type DifferentAsyncFormat
local function test4(x)
return x
end
test4(20) -- correctly tags as async
local function non_async()
test() -- if await-in-sync is enabled, this warns as expected
-- since the function is not tagged async
test2() -- gives no warning since its not tagged as async function
test3(2) -- gives no warns since its not tagged as async function
test4(4) -- warns as expected when await-in-sync is enabled
end
---@async
local function async_code()
test() -- no warning as expected when await-in-sync is enabled
test2()
test3(2)
test4(4) -- no warning as expected when await-in-sync is enabled
end
Normal alias with async fun():
Alias with generic with async fun():
Reproduction steps
Tested version: 3.19.1
Create an alias that has a generic beside the name, then hover the function or use it in a context where await-in-sync warning will appear.
Example:
---@alias MyAsyncFunc<T> async fun(): T
---@alias MyAsyncFuncNormal async fun(): any
---@type MyAsyncFunc<string>
local function my_function()
return "test"
end
---@type MyAsyncFuncNormal
local function working()
return "test"
end
---@diagnostic enable: await-in-sync
local function async_context()
my_function() -- should raise `await-in-sync` warning
working() -- warns with `await-in-sync`
end
Additional Notes
No response
Log File
No response
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 446
- Merge trung bình
- 8 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc 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.
Issue khác của LuaLS/lua-language-server
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
LuaLS/lua-language-server#1776 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
LuaLS/lua-language-server#3470 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
LuaLS/lua-language-server#3468 ·
-
泛型for迭代器的类型推导漏掉了带__call的类Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
LuaLS/lua-language-server#3463 · 5 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
LuaLS/lua-language-server#3461 ·
Tất cả issue của LuaLS/lua-language-server
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
bug: (profiler): E484 "Can't open file .../vim/_core/shared" when stopping profiler on Neovim 0.12Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
folke/snacks.nvim#2971 ·
-
severity: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
luainkernel/lunatik#1853 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 3 ngày