Skip to content

fix: another regression related to type narrow and generic since v3.10.1 #3088

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `FIX` incorrect argument skip pattern for `--check_out_path=`, which incorrectly skips the next argument
* `NEW` CLI: added `--help`.
* `CHG` default path for `--doc_out_path` is the current directory
* `FIX` incorrect argument skip pattern for `--check_out_path=`, which incorrectly skips the next argument
* `FIX` incorrect error message for `--doc_update`.
* `FIX` reimplement section `luals.config` in file doc.json
* `FIX` incorrect file names in file doc.json
* `FIX` remove extra `./` path prefix in the check report when using `--check=.`
* `NEW` CLI: added `--help`.
* `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)

## 3.13.6
`2025-2-6`
Expand Down
15 changes: 3 additions & 12 deletions script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -641,20 +641,11 @@ local function matchCall(source)
newNode.originNode = myNode
vm.setNode(source, newNode, true)
if call.args then
-- clear existing node caches of args to allow recomputation with the type narrowed call
-- recompile existing node caches of args to allow recomputation with the type narrowed call
for _, arg in ipairs(call.args) do
if vm.getNode(arg) then
vm.setNode(arg, vm.createNode(), true)
end
end
for n in newNode:eachObject() do
if n.type == 'function'
or n.type == 'doc.type.function' then
for i, arg in ipairs(call.args) do
if vm.getNode(arg) and n.args[i] then
vm.setNode(arg, vm.compileNode(n.args[i]))
end
end
vm.removeNode(arg)
vm.compileNode(arg)
end
end
end
Expand Down
40 changes: 40 additions & 0 deletions test/type_inference/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4718,6 +4718,46 @@ local function f(v) end
local <?r?> = f('')
]]

TEST 'A' [[
---@class A
local A = {}

---@generic T
---@param self T
---@param s string
---@return T
function A:f(s) end

---@generic T
---@param self T
---@param i integer
---@return T
function A:f(i) end

local <?r?> = A:f('')
]]

TEST 'B' [[
---@class A
local A = {}

---@generic T
---@param self T
---@param s string
---@return T
function A:f(s) end

---@generic T
---@param self T
---@param i integer
---@return T
function A:f(i) end

---@class B: A
local B = {}
local <?r?> = B:f('')
]]

TEST 'integer' [[
local function F(...)
local t = {...}
Expand Down