@@ -89,11 +89,27 @@ local function checkValue(parent, child)
8989 return true
9090end
9191
92+ --- @param name string
93+ --- @param suri uri
94+ --- @return boolean
95+ local function isAlias (name , suri )
96+ local global = vm .getGlobal (' type' , name )
97+ if not global then
98+ return false
99+ end
100+ for _ , set in ipairs (global :getSets (suri )) do
101+ if set .type == ' doc.alias' then
102+ return true
103+ end
104+ end
105+ return false
106+ end
107+
92108--- @param uri uri
93109--- @param child vm.node | string | vm.node.object
94110--- @param parent vm.node | string | vm.node.object
95111--- @param mark ? table
96- --- @return boolean
112+ --- @return boolean ?
97113function vm .isSubType (uri , child , parent , mark )
98114 mark = mark or {}
99115
@@ -109,31 +125,43 @@ function vm.isSubType(uri, child, parent, mark)
109125 for n in child :eachObject () do
110126 if getNodeName (n ) then
111127 hasKnownType = true
112- if vm .isSubType (uri , n , parent , mark ) then
128+ if vm .isSubType (uri , n , parent , mark ) == true then
113129 return true
114130 end
115131 end
116132 end
117133 return not hasKnownType
118134 else
119- local weakNil = config .get (uri , ' Lua.type.weakNilCheck' )
135+ local weakNil = config .get (uri , ' Lua.type.weakNilCheck' )
120136 for n in child :eachObject () do
121137 local nodeName = getNodeName (n )
122138 if nodeName
123139 and not (nodeName == ' nil' and weakNil )
124- and not vm .isSubType (uri , n , parent , mark ) then
140+ and vm .isSubType (uri , n , parent , mark ) == false then
125141 return false
126142 end
127143 end
128144 if not weakNil and child :isOptional () then
129- if not vm .isSubType (uri , ' nil' , parent , mark ) then
145+ if vm .isSubType (uri , ' nil' , parent , mark ) == false then
130146 return false
131147 end
132148 end
133149 return true
134150 end
135151 end
136152
153+ --- @cast child vm.node.object
154+ local childName = getNodeName (child )
155+ if childName == ' any'
156+ or childName == ' unknown' then
157+ return true
158+ end
159+
160+ if not childName
161+ or isAlias (childName , uri ) then
162+ return nil
163+ end
164+
137165 if type (parent ) == ' string' then
138166 local global = vm .getGlobal (' type' , parent )
139167 if not global then
@@ -143,35 +171,34 @@ function vm.isSubType(uri, child, parent, mark)
143171 elseif parent .type == ' vm.node' then
144172 for n in parent :eachObject () do
145173 if getNodeName (n )
146- and vm .isSubType (uri , child , n , mark ) then
174+ and vm .isSubType (uri , child , n , mark ) == true then
147175 return true
148176 end
149177 if n .type == ' doc.generic.name' then
150178 return true
151179 end
152180 end
153181 if parent :isOptional () then
154- if vm .isSubType (uri , child , ' nil' , mark ) then
182+ if vm .isSubType (uri , child , ' nil' , mark ) == true then
155183 return true
156184 end
157185 end
158186 return false
159187 end
160188
161- --- @cast child vm.node.object
162189 --- @cast parent vm.node.object
163190
164- local childName = getNodeName (child )
165191 local parentName = getNodeName (parent )
166- if childName == ' any'
167- or parentName == ' any'
168- or childName == ' unknown'
169- or parentName == ' unknown'
170- or not childName
171- or not parentName then
192+ if parentName == ' any'
193+ or parentName == ' unknown' then
172194 return true
173195 end
174196
197+ if not parentName
198+ or isAlias (parentName , uri ) then
199+ return nil
200+ end
201+
175202 if childName == parentName then
176203 if not checkValue (parent , child ) then
177204 return false
@@ -223,15 +250,11 @@ function vm.isSubType(uri, child, parent, mark)
223250 for _ , ext in ipairs (set .extends ) do
224251 if ext .type == ' doc.extends.name'
225252 and (not isBasicType or guide .isBasicType (ext [1 ]))
226- and vm .isSubType (uri , ext [1 ], parent , mark ) then
253+ and vm .isSubType (uri , ext [1 ], parent , mark ) == true then
227254 return true
228255 end
229256 end
230257 end
231- if set .type == ' doc.alias'
232- or set .type == ' doc.enum' then
233- return true
234- end
235258 end
236259 end
237260 mark [childName ] = nil
0 commit comments