From 28d829c86712ce5bc453feccc5129a32f78d80c0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 4 Dec 2018 15:01:42 -0200 Subject: Calls cannot be tail in the scope of a to-be-closed variable A to-be-closed variable must be closed when a block ends, so even a 'return foo()' cannot directly returns the results of 'foo'; the function must close the scope before returning. --- testes/locals.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'testes') diff --git a/testes/locals.lua b/testes/locals.lua index 24681dd9..340af61c 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -225,21 +225,24 @@ end do - -- to-be-closed variables must be closed in tail calls + -- calls cannot be tail in the scope of to-be-closed variables local X, Y local function foo () local *toclose _ = function () Y = 10 end - assert(X == 20 and Y == nil) + assert(X == true and Y == nil) -- 'X' not closed yet return 1,2,3 end local function bar () - local *toclose _ = function () X = 20 end - return foo() + local *toclose _ = function () X = false end + X = true + do + return foo() -- not a tail call! + end end local a, b, c, d = bar() - assert(a == 1 and b == 2 and c == 3 and X == 20 and Y == 10 and d == nil) + assert(a == 1 and b == 2 and c == 3 and X == false and Y == 10 and d == nil) end -- cgit v1.2.3-55-g6feb