summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-03-13 19:21:40 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-03-13 19:21:40 +0800
commit6ef1608d857e0179c4db7a14037df84dbef676c8 (patch)
treeb007e893750d513427db64f4eb04ece13c6ce787
parent671d9526cbfa83c01e74aa3405f1d32b647822d7 (diff)
downloadlua-language-server-6ef1608d857e0179c4db7a14037df84dbef676c8.zip
look into unions for operators
fix #1996
-rw-r--r--changelog.md2
-rw-r--r--script/vm/operator.lua21
-rw-r--r--test/type_inference/init.lua15
3 files changed, 31 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md
index a0ad84a5..8b1537c8 100644
--- a/changelog.md
+++ b/changelog.md
@@ -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`
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index 48e29304..9c68e648 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -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
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 66fa8768..bc70fbf4 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -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
+]]