@@ -115,13 +115,35 @@ return function (uri, callback)
115115 local function checkExtraTableField (src )
116116 await .delay ()
117117
118- if not src .bindSource then
119- return
120- end
121- if not vm .docHasAttr (src , ' exact' ) then
122- return
118+ local value
119+ if src .type == ' table' then
120+ -- any table with a class type should not allow field injection
121+ local isTyped = false
122+ for _ , def in ipairs (vm .getDefs (src )) do
123+ -- logic below is largely based on `missing-fields` diagnostics
124+ if def .type == ' doc.class' then
125+ if def .bindSource
126+ and guide .isInRange (def .bindSource , src .start )
127+ then
128+ -- this is a table binded with `@class`, will be checked in `doc.class` case
129+ return
130+ end
131+ isTyped = true
132+ end
133+ end
134+ if not isTyped then
135+ return
136+ end
137+ value = src
138+ elseif src .type == ' doc.class' then
139+ if not src .bindSource then
140+ return
141+ end
142+ if not vm .docHasAttr (src , ' exact' ) then
143+ return
144+ end
145+ value = src .bindSource .value
123146 end
124- local value = src .bindSource .value
125147 if not value or value .type ~= ' table' then
126148 return
127149 end
@@ -134,7 +156,7 @@ return function (uri, callback)
134156 end
135157 local message = lang .script (' DIAG_INJECT_FIELD' , {
136158 class = vm .getInfer (src ):view (uri ),
137- field = guide .getKeyName (src ),
159+ field = guide .getKeyName (field ),
138160 fix = ' ' ,
139161 })
140162 callback {
@@ -147,4 +169,5 @@ return function (uri, callback)
147169 end
148170
149171 guide .eachSourceType (ast .ast , ' doc.class' , checkExtraTableField )
172+ guide .eachSourceType (ast .ast , ' table' , checkExtraTableField )
150173end
0 commit comments