Skip to content

Commit

Permalink
fix: preserve vararg info in recursive function definition
Browse files Browse the repository at this point in the history
Fixes #727
  • Loading branch information
hishamhm committed Jan 5, 2024
1 parent a9f2e9c commit 4478a82
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions spec/call/function_spec.lua
Expand Up @@ -11,4 +11,25 @@ describe("function calls", function()
]], {
{ y = 6, msg = "variable is not being assigned a value" },
}))

it("can perform recursive calls on varargs (regression test for #727)", util.check([[
local message:string = "hello world!"
local function foo(...: string): string
local n = select("#", ...)
if n < 3 then
return ""
end
if message ~= "hello world" then
return foo("hi there", select(2, ...))
else
local r = {"hi there", select(2, ...)}
return foo(table.unpack(r))
end
end
local function bar(...: string): string
return foo("hi there", select(2, ...))
end
]]))
end)
2 changes: 1 addition & 1 deletion tl.lua
Expand Up @@ -7918,7 +7918,7 @@ tl.type_check = function(ast, opts)
end

local function add_function_definition_for_recursion(node)
local args = a_type({ typename = "tuple" })
local args = a_type({ typename = "tuple", is_va = node.args.type.is_va })
for _, fnarg in ipairs(node.args) do
table.insert(args, fnarg.type)
end
Expand Down
2 changes: 1 addition & 1 deletion tl.tl
Expand Up @@ -7918,7 +7918,7 @@ tl.type_check = function(ast: Node, opts: TypeCheckOptions): Result, string
end

local function add_function_definition_for_recursion(node: Node)
local args: Type = a_type { typename = "tuple" }
local args: Type = a_type { typename = "tuple", is_va = node.args.type.is_va }
for _, fnarg in ipairs(node.args) do
table.insert(args, fnarg.type)
end
Expand Down

0 comments on commit 4478a82

Please sign in to comment.