Conversation
There was a problem hiding this comment.
中文:该修复将 content == 'async' 替换为 checkToken('name', 'async', 1),使 async 前缀检测仅在 token 类型为 name 时触发,从而避免把 LuaDoc 类型中的字符串字面量 "async"(token 类型为 string)误判为 async fun 前缀。这一改动方向正确,且新增的 AST 测试覆盖了 ---@field mode "async" | "sync" 场景。建议确认 checkToken 的第三个参数 1 语义为“向前查看 1 个 token 且不消费”,并确认 checkToken 在文件作用域内已定义、在 parseFunction 调用点可用;同时建议补充一个仍能正确解析 ---@async fun 前缀的回归测试,以防该改动意外破坏原有 async 前缀功能。
English: The fix replaces content == 'async' with checkToken('name', 'async', 1), so the async prefix detection only triggers when the token type is name, avoiding mis-parsing the string literal "async" (token type string) inside LuaDoc types as the async fun prefix. The direction is correct, and the added AST test covers the ---@field mode "async" | "sync" case. Please confirm that the third argument 1 of checkToken means "look ahead 1 token without consuming it", and that checkToken is defined in file scope and available at the parseFunction call site. Also consider adding a regression test that still parses the ---@async fun prefix correctly, to ensure this change does not accidentally break the existing async prefix behavior.
Summary
parseFunctionnow accepts theasync funprefix only when the token type isname, the same wayparseTypeUnitFunctionalready recognizesfun.async fun(...)is unchanged.asyncas theasync funprefix and consumed it. A string literal"async"(for example---@field mode "async" | "sync") produced<type name> expected.and the rest of the union was lost. When"async"was the second arm ("sync" | "async"), the first arm was kept and"async"was dropped with no warning.FIXlinks literal strings 'async' is mis-parsed #3402.Decision
checkToken('name', 'async', 1)before consuming the token. That is how this file already distinguishes thefunkeyword from other tokens; it is the smallest reversible change that stops consuming a string"async".peekToken()astp == 'name' and content == 'async', and/or apply the same kind check to"fun". Happy to switch to the explicit type compare, or to extend the guard to"fun", if you prefer. ("fun"already survives today becauseparseTypeUnitFunctionchecks token type before consuming.)Test plan
parser_testAST fixture---@field mode "async" | "sync"(fails without the parser change; passes with it)---@type async fun()still parses as an async function type (existing hover coverage)Fixes #3402