Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve typeargs when both types in 'or' match expected type #709

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading