Skip to content

Commit 6ef1608

Browse files
committed
look into unions for operators
fix #1996
1 parent 671d952 commit 6ef1608

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
## 3.6.18
44
* `FIX` [#1943]
5+
* `FIX` [#1996]
56

67
[#1943]: https://github.com/LuaLS/lua-language-server/issues/1943
8+
[#1996]: https://github.com/LuaLS/lua-language-server/issues/1996
79

810
## 3.6.17
911
`2023-3-9`

script/vm/operator.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,22 @@ local function checkOperators(operators, op, value, result)
7373
local valueNode = vm.compileNode(value)
7474
local expNode = vm.compileNode(operator.exp)
7575
local uri = guide.getUri(operator)
76-
if not vm.isSubType(uri, valueNode, expNode) then
77-
goto CONTINUE
76+
for vo in valueNode:eachObject() do
77+
if vm.isSubType(uri, vo, expNode) then
78+
if not result then
79+
result = vm.createNode()
80+
end
81+
result:merge(vm.compileNode(operator.extends))
82+
return result
83+
end
7884
end
85+
else
86+
if not result then
87+
result = vm.createNode()
88+
end
89+
result:merge(vm.compileNode(operator.extends))
90+
return result
7991
end
80-
if not result then
81-
result = vm.createNode()
82-
end
83-
result:merge(vm.compileNode(operator.extends))
84-
break
8592
::CONTINUE::
8693
end
8794
return result

test/type_inference/init.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,3 +4239,18 @@ TEST 'number' [[
42394239
local n
42404240
local <?v?> = n or error('')
42414241
]]
4242+
4243+
TEST 'Foo' [[
4244+
---@class Foo
4245+
---@operator mul(Foo): Foo
4246+
---@operator mul(Bar): Foo
4247+
---@class Bar
4248+
4249+
---@type Foo
4250+
local foo
4251+
4252+
---@type Foo|Bar
4253+
local fooOrBar
4254+
4255+
local <?b?> = foo * fooOrBar
4256+
]]

0 commit comments

Comments
 (0)