Skip to content

Commit 24b9faa

Browse files
authored
Merge pull request #3247 from Cooldude2606/fix/3246
Fix: Stack overflow while attempting to resolve function return value
2 parents 7dd611a + cf6c60e commit 24b9faa

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* `FIX` adds the `|lambda|` operator to the `Lua.runtime.nonstandardSymbol` configuration template, which allows the use of that option. Previously, support for it existed in the parser, but we could not actually use the option because it is not recognised in the configuration.
88
* `FIX` Typed `@field` (eg `---@field [string] boolean`) should not override other defined field [#2171](https://github.com/LuaLS/lua-language-server/issues/2171), [#2711](https://github.com/LuaLS/lua-language-server/issues/2711)
99
* `FIX` don't return empty hover doc when luals failed to find definition
10+
* `FIX` Prevent stack overflow when attempting to resolve function return values. [#3246](https://github.com/LuaLS/lua-language-server/issues/3246)
1011

1112
## 3.15.0
1213
`2025-6-25`

script/vm/sign.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ function mt:resolve(uri, args)
3030

3131
---@type table<string, vm.node>
3232
local resolved = {}
33+
---@type table<string, boolean>
34+
local visited = {}
3335

3436
---@param object vm.node|vm.node.object
3537
---@param node vm.node
3638
local function resolve(object, node)
39+
local visitedHash = ("%s|%s"):format(object, node)
40+
if visited[visitedHash] then
41+
return -- prevent circular resolve calls by only visiting each pair once
42+
end
43+
visited[visitedHash] = true
3744
if object.type == 'vm.node' then
3845
for o in object:eachObject() do
3946
resolve(o, node)

test/type_inference/common.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4881,3 +4881,25 @@ end
48814881
48824882
local a, b, <?c?>, d = unpack(t)
48834883
]]
4884+
4885+
-- Test for overflow in circular resolve, only pass requirement is no overflow
4886+
TEST 'Callback<<T>>|fun():fun():fun():Success, string' [[
4887+
--- @alias Success fun(): Success
4888+
--- @alias Callback<T> fun(): Success, T
4889+
4890+
--- @return Success
4891+
local function success()
4892+
return success
4893+
end
4894+
4895+
--- @generic T
4896+
--- @param callback Callback<T>
4897+
--- @return Callback<T>
4898+
local function make_callback(callback)
4899+
return callback
4900+
end
4901+
4902+
local <?callback?> = make_callback(function()
4903+
return success, ""
4904+
end)
4905+
]]

0 commit comments

Comments
 (0)