Skip to content

Commit

Permalink
fix: resolve typeargs when both types in 'or' match expected type (#709)
Browse files Browse the repository at this point in the history
Fixes #706.
  • Loading branch information
hishamhm authored Oct 20, 2023
1 parent fc5339e commit 821e161
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions spec/operator/or_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,11 @@ describe("or", function()
local x: string | number = "hello" or "world"
]]))

it("resolves type arguments when both types in 'or' match expected type (regression test for #706)", util.check([[
local t1: {string:number} = { foo = 42 }
local t2: {string:number} = { foo = 42 }
for _, v in pairs(t1 or t2) do
print(v * v)
end
]]))
end)
2 changes: 1 addition & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9969,7 +9969,7 @@ tl.type_check = function(ast, opts)
local a_is = is_a(a, node.expected)
local b_is = is_a(b, node.expected)
if a_is and b_is then
node.type = node.expected
node.type = resolve_typevars_at(node, node.expected)
elseif a_is then
node.type = resolve_tuple(b)
else
Expand Down
2 changes: 1 addition & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -9969,7 +9969,7 @@ tl.type_check = function(ast: Node, opts: TypeCheckOptions): Result, string
local a_is = is_a(a, node.expected)
local b_is = is_a(b, node.expected)
if a_is and b_is then
node.type = node.expected
node.type = resolve_typevars_at(node, node.expected)
elseif a_is then
node.type = resolve_tuple(b)
else
Expand Down

0 comments on commit 821e161

Please sign in to comment.