@@ -63,6 +63,54 @@ function vm.countParamsOfFunction(func)
6363 return min , max , def
6464end
6565
66+ --- @param source parser.object
67+ --- @return integer min
68+ --- @return number max
69+ --- @return integer def
70+ function vm .countParamsOfSource (source )
71+ local min = 0
72+ local max = 0
73+ local def = 0
74+ local overloads = {}
75+ if source .bindDocs then
76+ for _ , doc in ipairs (source .bindDocs ) do
77+ if doc .type == ' doc.overload' then
78+ overloads [doc .overload ] = true
79+ end
80+ end
81+ end
82+ local hasDocFunction
83+ for nd in vm .compileNode (source ):eachObject () do
84+ if nd .type == ' doc.type.function' and not overloads [nd ] then
85+ hasDocFunction = true
86+ --- @cast nd parser.object
87+ local dmin , dmax , ddef = vm .countParamsOfFunction (nd )
88+ if dmin > min then
89+ min = dmin
90+ end
91+ if dmax > max then
92+ max = dmax
93+ end
94+ if ddef > def then
95+ def = ddef
96+ end
97+ end
98+ end
99+ if not hasDocFunction then
100+ local dmin , dmax , ddef = vm .countParamsOfFunction (source )
101+ if dmin > min then
102+ min = dmin
103+ end
104+ if dmax > max then
105+ max = dmax
106+ end
107+ if ddef > def then
108+ def = ddef
109+ end
110+ end
111+ return min , max , def
112+ end
113+
66114--- @param node vm.node
67115--- @return integer min
68116--- @return number max
@@ -136,12 +184,12 @@ function vm.countReturnsOfFunction(func, onlyDoc, mark)
136184 end
137185 if not onlyDoc and not hasDocReturn and func .returns then
138186 for _ , ret in ipairs (func .returns ) do
139- local rmin , rmax , ddef = vm .countList (ret , mark )
140- if not min or rmin < min then
141- min = rmin
187+ local dmin , dmax , ddef = vm .countList (ret , mark )
188+ if not min or dmin < min then
189+ min = dmin
142190 end
143- if not max or rmax > max then
144- max = rmax
191+ if not max or dmax > max then
192+ max = dmax
145193 end
146194 if not def or ddef > def then
147195 def = ddef
@@ -156,6 +204,62 @@ function vm.countReturnsOfFunction(func, onlyDoc, mark)
156204 error (' not a function' )
157205end
158206
207+ --- @param source parser.object
208+ --- @return integer min
209+ --- @return number max
210+ --- @return integer def
211+ function vm .countReturnsOfSource (source )
212+ local overloads = {}
213+ local hasDocFunction
214+ local min , max , def
215+ if source .bindDocs then
216+ for _ , doc in ipairs (source .bindDocs ) do
217+ if doc .type == ' doc.overload' then
218+ overloads [doc .overload ] = true
219+ local dmin , dmax , ddef = vm .countReturnsOfFunction (doc .overload )
220+ if not min or dmin < min then
221+ min = dmin
222+ end
223+ if not max or dmax > max then
224+ max = dmax
225+ end
226+ if not def or ddef > def then
227+ def = ddef
228+ end
229+ end
230+ end
231+ end
232+ for nd in vm .compileNode (source ):eachObject () do
233+ if nd .type == ' doc.type.function' and not overloads [nd ] then
234+ --- @cast nd parser.object
235+ hasDocFunction = true
236+ local dmin , dmax , ddef = vm .countReturnsOfFunction (nd )
237+ if not min or dmin < min then
238+ min = dmin
239+ end
240+ if not max or dmax > max then
241+ max = dmax
242+ end
243+ if not def or ddef > def then
244+ def = ddef
245+ end
246+ end
247+ end
248+ if not hasDocFunction then
249+ local dmin , dmax , ddef = vm .countReturnsOfFunction (source , true )
250+ if not min or dmin < min then
251+ min = dmin
252+ end
253+ if not max or dmax > max then
254+ max = dmax
255+ end
256+ if not def or ddef > def then
257+ def = ddef
258+ end
259+ end
260+ return min , max , def
261+ end
262+
159263--- @param func parser.object
160264--- @param mark ? table
161265--- @return integer min
@@ -254,7 +358,7 @@ function vm.isVarargFunctionWithOverloads(func)
254358 if not func .args then
255359 return false
256360 end
257- if func .args [1 ].type ~= ' ...' then
361+ if not func . args [ 1 ] or func .args [1 ].type ~= ' ...' then
258362 return false
259363 end
260364 if not func .bindDocs then
0 commit comments