Skip to content

Conversation

tomlau10
Copy link
Contributor

@tomlau10 tomlau10 commented Jul 6, 2025

fixes #2171, fixes #2711

The problem

I found these issues while discussing in #3221.
In short, the typed @field [T1] T2 should only apply when no types found for that specific key.
I found a fix after some debugging, implementation details: #3221 (comment)

before

---@class A
---@field [string] boolean
local A
function A:f() end

local a = A.a   --> boolean ✅
local f = A.f   --> boolean|function ❌

after

---@class A
---@field [string] boolean
local A
function A:f() end

local a = A.a   --> boolean ✅
local f = A.f   --> function ✅

中文版

@field [T1] T2 似應該只在對應 key 找不到任何 type define 時才 apply
解決方式是簡單將相關 infer logic 延後到查找完 class variable 的 setfield/setmethod 之後才處理

@sumneko sumneko merged commit 35ed907 into LuaLS:master Jul 15, 2025
11 checks passed
@sumneko
Copy link
Collaborator

sumneko commented Jul 15, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typed field overrides the type of other fields Annotation field [string] any prevents to define functions
2 participants