Skip to content

Commit

Permalink
fix: let lax mode perform emptytable key-value inference as normal
Browse files Browse the repository at this point in the history
Do not over-constrain types with `unknown`, let `assert_is_a`
perform the check when t2 is `unresolved_emptytable_value`.
  • Loading branch information
hishamhm committed Jan 26, 2024
1 parent 90b6be4 commit 20336fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions spec/lax/lax_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 20336fa

Please sign in to comment.