Skip to content

Commit 4b52ebf

Browse files
Prevent circular resolve
Fixes: #3246 Co-authored-by: Tom Lau <tomandfatboy@gmail.com>
1 parent 7dd611a commit 4b52ebf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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 resolving = {}
3335

3436
---@param object vm.node|vm.node.object
3537
---@param node vm.node
3638
local function resolve(object, node)
39+
local resolveHash = ("%s|%s"):format(object, node)
40+
if resolving[resolveHash] then
41+
return -- prevent circular resolve calls
42+
end
43+
resolving[resolveHash] = 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)