Skip to content

Commit 2276dc2

Browse files
committed
Fix generic class method resolution for @param self list<T> pattern
1 parent eb1135e commit 2276dc2

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

script/vm/compiler.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,18 @@ local function bindReturnOfFunction(source, mfunc, index, args)
16931693
hasUnresolvedGeneric = true
16941694
break
16951695
end
1696+
-- Also check inside doc.type.sign for unresolved generics
1697+
-- (e.g. list<T> where T is not yet resolved)
1698+
if rnode.type == 'doc.type.sign' and rnode.signs then
1699+
guide.eachSourceType(rnode, 'doc.generic.name', function (src)
1700+
if not src._resolved then
1701+
hasUnresolvedGeneric = true
1702+
end
1703+
end)
1704+
if hasUnresolvedGeneric then
1705+
break
1706+
end
1707+
end
16961708
end
16971709
if hasUnresolvedGeneric then
16981710
local sign = vm.getSign(mfunc)

script/vm/generic.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ local function cloneObject(source, resolved)
133133
for _, sign in ipairs(source.signs) do
134134
if sign.type == 'doc.type' then
135135
for _, tp in ipairs(sign.types) do
136-
if tp.type == 'doc.type.name' and resolved[tp[1]] then
136+
if (tp.type == 'doc.type.name' or tp.type == 'doc.generic.name') and resolved[tp[1]] then
137137
needsClone = true
138138
break
139139
end
140140
end
141-
elseif sign.type == 'doc.type.name' and resolved[sign[1]] then
141+
elseif (sign.type == 'doc.type.name' or sign.type == 'doc.generic.name') and resolved[sign[1]] then
142142
needsClone = true
143143
end
144144
if needsClone then break end

script/vm/sign.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ function mt:resolve(uri, args)
176176
end
177177
return
178178
end
179+
if object.type == 'doc.type.sign' and object.signs then
180+
-- list<T> -> list<string>: match sign parameters positionally
181+
for n in node:eachObject() do
182+
if n.type == 'doc.type.sign' and n.signs
183+
and n.node and object.node
184+
and n.node[1] == object.node[1] then
185+
for i, signParam in ipairs(object.signs) do
186+
if n.signs[i] then
187+
resolve(vm.compileNode(signParam), vm.compileNode(n.signs[i]))
188+
end
189+
end
190+
end
191+
end
192+
return
193+
end
179194
end
180195

181196
---@param sign vm.node
@@ -191,7 +206,8 @@ function mt:resolve(uri, args)
191206
end
192207
if obj.type == 'doc.type.table'
193208
or obj.type == 'doc.type.function'
194-
or obj.type == 'doc.type.array' then
209+
or obj.type == 'doc.type.array'
210+
or obj.type == 'doc.type.sign' then
195211
---@cast obj parser.object
196212
local hasGeneric
197213
guide.eachSourceType(obj, 'doc.generic.name', function (src)
@@ -203,7 +219,8 @@ function mt:resolve(uri, args)
203219
end
204220
end
205221
if obj.type == 'variable'
206-
or obj.type == 'local' then
222+
or obj.type == 'local'
223+
or obj.type == 'self' then
207224
goto CONTINUE
208225
end
209226
local view = vm.getInfer(obj):view(uri)

0 commit comments

Comments
 (0)