From e0819d8fa105c3e9ff90f081c4585796560d9888 Mon Sep 17 00:00:00 2001 From: Tom Lau Date: Sun, 23 Feb 2025 14:57:56 +0800 Subject: [PATCH] fix: another regression related to type narrow and generic since v3.10.1 --- changelog.md | 1 + script/vm/compiler.lua | 15 +++---------- test/type_inference/common.lua | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index 97605aa7e..fdaefa34e 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ * `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=.` +* `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` diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index cee5de55e..ed56e4508 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -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 diff --git a/test/type_inference/common.lua b/test/type_inference/common.lua index 5f0fd81a6..268f492b4 100644 --- a/test/type_inference/common.lua +++ b/test/type_inference/common.lua @@ -4718,6 +4718,46 @@ local function f(v) end local = 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 = 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 = B:f('') +]] + TEST 'integer' [[ local function F(...) local t = {...}