Skip to content

Commit

Permalink
look into unions for operators
Browse files Browse the repository at this point in the history
fix #1996
  • Loading branch information
sumneko committed Mar 13, 2023
1 parent 671d952 commit 6ef1608
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## 3.6.18
* `FIX` [#1943]
* `FIX` [#1996]

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

## 3.6.17
`2023-3-9`
Expand Down
21 changes: 14 additions & 7 deletions script/vm/operator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,22 @@ local function checkOperators(operators, op, value, result)
local valueNode = vm.compileNode(value)
local expNode = vm.compileNode(operator.exp)
local uri = guide.getUri(operator)
if not vm.isSubType(uri, valueNode, expNode) then
goto CONTINUE
for vo in valueNode:eachObject() do
if vm.isSubType(uri, vo, expNode) then
if not result then
result = vm.createNode()
end
result:merge(vm.compileNode(operator.extends))
return result
end
end
else
if not result then
result = vm.createNode()
end
result:merge(vm.compileNode(operator.extends))
return result
end
if not result then
result = vm.createNode()
end
result:merge(vm.compileNode(operator.extends))
break
::CONTINUE::
end
return result
Expand Down
15 changes: 15 additions & 0 deletions test/type_inference/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4239,3 +4239,18 @@ TEST 'number' [[
local n
local <?v?> = n or error('')
]]

TEST 'Foo' [[
---@class Foo
---@operator mul(Foo): Foo
---@operator mul(Bar): Foo
---@class Bar
---@type Foo
local foo
---@type Foo|Bar
local fooOrBar
local <?b?> = foo * fooOrBar
]]

0 comments on commit 6ef1608

Please sign in to comment.