Skip to content

Commit 6207297

Browse files
committed
fix: resolve typeargs when both types in 'or' match expected type
Fixes #706.
1 parent fc5339e commit 6207297

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

spec/operator/or_spec.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,11 @@ describe("or", function()
128128
local x: string | number = "hello" or "world"
129129
]]))
130130

131+
it("resolves type arguments when both types in 'or' match expected type (regression test for #706)", util.check([[
132+
local t1: {string:number} = { foo = 42 }
133+
local t2: {string:number} = { foo = 42 }
134+
for _, v in pairs(t1 or t2) do
135+
print(v * v)
136+
end
137+
]]))
131138
end)

tl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9969,7 +9969,7 @@ tl.type_check = function(ast, opts)
99699969
local a_is = is_a(a, node.expected)
99709970
local b_is = is_a(b, node.expected)
99719971
if a_is and b_is then
9972-
node.type = node.expected
9972+
node.type = resolve_typevars_at(node, node.expected)
99739973
elseif a_is then
99749974
node.type = resolve_tuple(b)
99759975
else

tl.tl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9969,7 +9969,7 @@ tl.type_check = function(ast: Node, opts: TypeCheckOptions): Result, string
99699969
local a_is = is_a(a, node.expected)
99709970
local b_is = is_a(b, node.expected)
99719971
if a_is and b_is then
9972-
node.type = node.expected
9972+
node.type = resolve_typevars_at(node, node.expected)
99739973
elseif a_is then
99749974
node.type = resolve_tuple(b)
99759975
else

0 commit comments

Comments
 (0)