Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Async flag lost when alias with type parameters (@alias Name<T> async fun) is used

未關閉
#3,469 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
68/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
lua
領域
compilers

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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():
Image

Alias with generic with async fun():
Image

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

主要語言
Lua
星號
4.4k
分支
446
平均合併
8 天 9 小時
30 天內合併 PR
1

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

LuaLS/lua-language-server 的其他 Issue

查看 LuaLS/lua-language-server 的全部 Issue

相似的 Issue

更多 Lua Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。