Skip to content

fix: typed @field should not override other defined field #3224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 之後才處理

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
1 participant