diff --git a/changelog.md b/changelog.md index daefdb5ae..af1f653e4 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `FIX` Generic aliases of async functions (e.g. `---@alias Name async fun(): T` used as `Name`) keep the `async` flag, so `await-in-sync` and hover treat them as async [#3469](https://github.com/LuaLS/lua-language-server/issues/3469) ## 3.19.2 `2026-10-13` diff --git a/script/vm/generic.lua b/script/vm/generic.lua index 0b171622c..db46a5eeb 100644 --- a/script/vm/generic.lua +++ b/script/vm/generic.lua @@ -113,6 +113,8 @@ local function cloneObject(source, resolved) start = source.start, finish = source.finish, parent = source.parent, + async = source.async, + asyncPos = source.asyncPos, args = {}, returns = {}, } diff --git a/test/diagnostics/await-in-sync.lua b/test/diagnostics/await-in-sync.lua index 323c11137..1c8da1d8d 100644 --- a/test/diagnostics/await-in-sync.lua +++ b/test/diagnostics/await-in-sync.lua @@ -130,3 +130,53 @@ end return af ]] + +TEST [[ +---@alias AsyncGenericFunc async fun(): T + +---@type AsyncGenericFunc +local f + +function F() + () +end +]] + +TEST [[ +---@alias AsyncGenericFunc async fun(x: T) + +---@type AsyncGenericFunc +local f + +---@async +function F() + f(1) +end +]] + +TEST [[ +---@alias AsyncGenericFunc async fun(): T + +---@class AsyncGenericHolder +---@field run AsyncGenericFunc + +---@type AsyncGenericHolder +local holder + +function F() + () +end +]] + +TEST [[ +---@alias AsyncGenericFunc async fun(): T + +---@type AsyncGenericFunc +local function f() + return 'x' +end + +function F() + () +end +]] diff --git a/test/hover/init.lua b/test/hover/init.lua index dbe245ad4..415657e2c 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1812,6 +1812,16 @@ local local f: async fun() ]] +TEST [[ +---@alias AsyncGenericFunc async fun(): T + +---@type AsyncGenericFunc +local +]] +[[ +local f: async AsyncGenericFunc +]] + config.set(nil, 'Lua.runtime.nonstandardSymbol', { '//' }) TEST [[ local = 1 // 2