From 6b8c4d33b02d0a4e4449b1dc59cb73a08dbddbc7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 26 Jan 2024 17:59:14 -0300 Subject: [PATCH] fix: lax arity of returns in function literals The unwanted difference between the types for `f` and `g` in the regression test from this commit was observed when fixing the issue #736. --- spec/lax/lax_spec.lua | 23 +++++++++++++++++++++++ tl.lua | 2 +- tl.tl | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/spec/lax/lax_spec.lua b/spec/lax/lax_spec.lua index 92a9d6061..f3047374b 100644 --- a/spec/lax/lax_spec.lua +++ b/spec/lax/lax_spec.lua @@ -20,4 +20,27 @@ describe("lax mode", function() { msg = "three" }, { msg = "data" }, })) + + it("defines lax arity of returns in function literals (#736)", util.lax_check([[ + -- f: function(unknown...):unknown... + local f = function() + return function() end + end + + for a, b in f() do + end + + -- g: function(unknown...):unknown... + local function g() + return function() end + end + + for x, y in g() do + end + ]], { + { msg = "a" }, + { msg = "b" }, + { msg = "x" }, + { msg = "y" }, + })) end) diff --git a/tl.lua b/tl.lua index 5541e8ee2..b18dfb7d1 100644 --- a/tl.lua +++ b/tl.lua @@ -11373,7 +11373,7 @@ self:expand_type(node, values, elements) }) min_arity = node.min_arity, typeargs = node.typeargs, args = args, - rets = rets, + rets = self.get_rets(rets), })) end, }, diff --git a/tl.tl b/tl.tl index a021db2f3..35f6ce292 100644 --- a/tl.tl +++ b/tl.tl @@ -11373,7 +11373,7 @@ do min_arity = node.min_arity, typeargs = node.typeargs, args = args, - rets = rets, + rets = self.get_rets(rets), })) end, },