5050--- @param parentName string
5151--- @param child vm.node.object
5252--- @param uri uri
53+ --- @param mark table
5354--- @param errs ? typecheck.err[]
5455--- @return boolean ?
55- local function checkEnum (parentName , child , uri , errs )
56+ local function checkParentEnum (parentName , child , uri , mark , errs )
5657 local parentClass = vm .getGlobal (' type' , parentName )
5758 if not parentClass then
5859 return nil
@@ -70,7 +71,7 @@ local function checkEnum(parentName, child, uri, errs)
7071 if child .type == ' global' then
7172 --- @cast child vm.global
7273 for _ , enum in ipairs (enums ) do
73- if vm .isSubType (uri , child , vm .compileNode (enum )) then
74+ if vm .isSubType (uri , child , vm .compileNode (enum ), mark ) then
7475 return true
7576 end
7677 end
@@ -131,6 +132,35 @@ local function checkEnum(parentName, child, uri, errs)
131132 end
132133end
133134
135+ --- @param childName string
136+ --- @param parent vm.node.object
137+ --- @param uri uri
138+ --- @param mark table
139+ --- @param errs ? typecheck.err[]
140+ --- @return boolean ?
141+ local function checkChildEnum (childName , parent , uri , mark , errs )
142+ local childClass = vm .getGlobal (' type' , childName )
143+ if not childClass then
144+ return nil
145+ end
146+ local enums
147+ for _ , set in ipairs (childClass :getSets (uri )) do
148+ if set .type == ' doc.enum' then
149+ enums = vm .getEnums (set )
150+ break
151+ end
152+ end
153+ if not enums then
154+ return nil
155+ end
156+ for _ , enum in ipairs (enums ) do
157+ if not vm .isSubType (uri , vm .compileNode (enum ), parent , mark ,errs ) then
158+ return false
159+ end
160+ end
161+ return true
162+ end
163+
134164--- @param parent vm.node.object
135165--- @param child vm.node.object
136166--- @param mark table
@@ -389,9 +419,14 @@ function vm.isSubType(uri, child, parent, mark, errs)
389419 return true
390420 end
391421
392- local isEnum = checkEnum (parentName , child , uri , errs )
393- if isEnum ~= nil then
394- return isEnum
422+ local result = checkParentEnum (parentName , child , uri , mark , errs )
423+ if result ~= nil then
424+ return result
425+ end
426+
427+ result = checkChildEnum (childName , parent , uri , mark , errs )
428+ if result ~= nil then
429+ return result
395430 end
396431
397432 if parentName == ' table' and not guide .isBasicType (childName ) then
0 commit comments