From 64a0fc57944ea9f045ed9ba18d96bc2bf2e13a8d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 19 Jul 2024 13:46:54 -0300 Subject: [PATCH] fix: can use nested records in global 'table' record --- spec/declaration/local_spec.lua | 5 +++++ tl.lua | 2 +- tl.tl | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/declaration/local_spec.lua b/spec/declaration/local_spec.lua index a1ae1b45a..6b93b8b1b 100644 --- a/spec/declaration/local_spec.lua +++ b/spec/declaration/local_spec.lua @@ -98,6 +98,11 @@ describe("local", function() { msg = "b" }, })) + it("local type can declare a type alias for table", util.check([[ + local type PackTable = table.PackTable + local args: table.PackTable = table.pack(1, 2, 3) + ]])) + it("local type can declare a nominal type alias (regression test for #238)", function () util.mock_io(finally, { ["module.tl"] = [[ diff --git a/tl.lua b/tl.lua index da4af9cd9..e6fdfad49 100644 --- a/tl.lua +++ b/tl.lua @@ -2586,7 +2586,7 @@ do local st = simple_types[tk] if st then return i + 1, new_type(ps, i, tk) - elseif tk == "table" then + elseif tk == "table" and ps.tokens[i + 1].tk ~= "." then local typ = new_type(ps, i, "map") typ.keys = new_type(ps, i, "any") typ.values = new_type(ps, i, "any") diff --git a/tl.tl b/tl.tl index 808a8bb5d..f949fcaca 100644 --- a/tl.tl +++ b/tl.tl @@ -2586,7 +2586,7 @@ local function parse_simple_type_or_nominal(ps: ParseState, i: integer): integer local st = simple_types[tk as TypeName] if st then return i + 1, new_type(ps, i, tk as TypeName) - elseif tk == "table" then + elseif tk == "table" and ps.tokens[i + 1].tk ~= "." then local typ = new_type(ps, i, "map") as MapType typ.keys = new_type(ps, i, "any") typ.values = new_type(ps, i, "any")