Skip to content

Commit e0819d8

Browse files
committed
fix: another regression related to type narrow and generic since v3.10.1
1 parent 64c7084 commit e0819d8

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* `FIX` reimplement section `luals.config` in file doc.json
99
* `FIX` incorrect file names in file doc.json
1010
* `FIX` remove extra `./` path prefix in the check report when using `--check=.`
11+
* `FIX` Another regression related to type narrow and generic param introduced since `v3.10.1` [#3087](https://github.com/LuaLS/lua-language-server/issues/3087)
1112

1213
## 3.13.6
1314
`2025-2-6`

script/vm/compiler.lua

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -641,20 +641,11 @@ local function matchCall(source)
641641
newNode.originNode = myNode
642642
vm.setNode(source, newNode, true)
643643
if call.args then
644-
-- clear existing node caches of args to allow recomputation with the type narrowed call
644+
-- recompile existing node caches of args to allow recomputation with the type narrowed call
645645
for _, arg in ipairs(call.args) do
646646
if vm.getNode(arg) then
647-
vm.setNode(arg, vm.createNode(), true)
648-
end
649-
end
650-
for n in newNode:eachObject() do
651-
if n.type == 'function'
652-
or n.type == 'doc.type.function' then
653-
for i, arg in ipairs(call.args) do
654-
if vm.getNode(arg) and n.args[i] then
655-
vm.setNode(arg, vm.compileNode(n.args[i]))
656-
end
657-
end
647+
vm.removeNode(arg)
648+
vm.compileNode(arg)
658649
end
659650
end
660651
end

test/type_inference/common.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4718,6 +4718,46 @@ local function f(v) end
47184718
local <?r?> = f('')
47194719
]]
47204720

4721+
TEST 'A' [[
4722+
---@class A
4723+
local A = {}
4724+
4725+
---@generic T
4726+
---@param self T
4727+
---@param s string
4728+
---@return T
4729+
function A:f(s) end
4730+
4731+
---@generic T
4732+
---@param self T
4733+
---@param i integer
4734+
---@return T
4735+
function A:f(i) end
4736+
4737+
local <?r?> = A:f('')
4738+
]]
4739+
4740+
TEST 'B' [[
4741+
---@class A
4742+
local A = {}
4743+
4744+
---@generic T
4745+
---@param self T
4746+
---@param s string
4747+
---@return T
4748+
function A:f(s) end
4749+
4750+
---@generic T
4751+
---@param self T
4752+
---@param i integer
4753+
---@return T
4754+
function A:f(i) end
4755+
4756+
---@class B: A
4757+
local B = {}
4758+
local <?r?> = B:f('')
4759+
]]
4760+
47214761
TEST 'integer' [[
47224762
local function F(...)
47234763
local t = {...}

0 commit comments

Comments
 (0)