From 20336fa92e20392cba90dac5fd1676458e068fdf 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 d30c3fc4f..0f4d83863 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 b1a2996dd..f9788be35 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