From 63f582816a2e1541c09618ff9296d8235b86bf0e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 26 Jan 2024 18:21:08 -0300 Subject: [PATCH] fix: let lax mode perform emptytable key-value inference as normal Do not over-constrain types with `unknown`, let `assert_is_a` perform the check when t2 is `unresolved_emptytable_value`. --- spec/lax/lax_spec.lua | 13 +++++++++++++ tl.lua | 2 +- tl.tl | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/lax/lax_spec.lua b/spec/lax/lax_spec.lua index f3047374b..e36b8d5b1 100644 --- a/spec/lax/lax_spec.lua +++ b/spec/lax/lax_spec.lua @@ -43,4 +43,17 @@ describe("lax mode", function() { msg = "x" }, { msg = "y" }, })) + + it("performs emptytable key-value inference as normal", util.lax_check([[ + local t = {} + + local s = "str" + + t[s] = 9 + + for k, v in pairs(t) do + print(k, v) + end + ]], {})) + end) diff --git a/tl.lua b/tl.lua index b18dfb7d1..220df52d8 100644 --- a/tl.lua +++ b/tl.lua @@ -8503,7 +8503,7 @@ a.types[i], b.types[i]), } function TypeChecker:assert_is_a(w, t1, t2, ctx, name) t1 = resolve_tuple(t1) t2 = resolve_tuple(t2) - if self.feat_lax and (is_unknown(t1) or is_unknown(t2)) then + if self.feat_lax and (is_unknown(t1) or t2.typename == "unknown") then return true end diff --git a/tl.tl b/tl.tl index 35f6ce292..0ae28817e 100644 --- a/tl.tl +++ b/tl.tl @@ -8503,7 +8503,7 @@ do function TypeChecker:assert_is_a(w: Where, t1: Type, t2: Type, ctx?: string | Node, name?: string): boolean t1 = resolve_tuple(t1) t2 = resolve_tuple(t2) - if self.feat_lax and (is_unknown(t1) or is_unknown(t2)) then + if self.feat_lax and (is_unknown(t1) or t2 is UnknownType) then return true end