From 97607d5e7cf3811ade81390e169d221013f68d29 Mon Sep 17 00:00:00 2001 From: ybai08 <271969568+ybai08@users.noreply.github.com> Date: Sun, 18 Oct 2026 03:38:59 -0500 Subject: [PATCH] fix: keep async flag when instantiating generic function aliases cloneObject rebuilt doc.type.function without copying `async`/`asyncPos`, so `---@alias Name async fun(): T` lost its async flag once used as `Name`, and await-in-sync/hover treated it as a sync function. Fixes #3469 --- changelog.md | 1 + script/vm/generic.lua | 2 ++ test/diagnostics/await-in-sync.lua | 50 ++++++++++++++++++++++++++++++ test/hover/init.lua | 10 ++++++ 4 files changed, 63 insertions(+) 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