Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve typeargs when both types in 'or' match expected type
Browse files Browse the repository at this point in the history
Fixes #706.
hishamhm committed Oct 20, 2023
1 parent fc5339e commit 6207297
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
@@ -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
@@ -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
2 changes: 1 addition & 1 deletion tl.tl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6207297

Please sign in to comment.