diff --git a/spec/call/function_spec.lua b/spec/call/function_spec.lua index b3489b65..31f26b9e 100644 --- a/spec/call/function_spec.lua +++ b/spec/call/function_spec.lua @@ -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) diff --git a/tl.lua b/tl.lua index 3d1f2a76..8d99203f 100644 --- a/tl.lua +++ b/tl.lua @@ -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 diff --git a/tl.tl b/tl.tl index 8291157c..e0278f55 100644 --- a/tl.tl +++ b/tl.tl @@ -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