summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-03-27 16:46:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-03-27 16:46:59 +0800
commit4399ca74c753c8822a62a2174ab2f47cefe98dca (patch)
tree7256a41378b56426b456a7800271c8591733ccb4
parent114695a4db97d9a1fe88a29fd2905f4ccb06ce45 (diff)
downloadlua-language-server-4399ca74c753c8822a62a2174ab2f47cefe98dca.zip
check operator `/`, `^` and `//`
fix #2036
-rw-r--r--changelog.md5
-rw-r--r--script/vm/operator.lua21
-rw-r--r--test/type_inference/init.lua7
3 files changed, 33 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index 84815b7c..4bad6917 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,10 @@
# changelog
+## 3.6.19
+* `FIX` [#2036]
+
+[#2036]: https://github.com/LuaLS/lua-language-server/issues/2036
+
## 3.6.18
`2023-3-23`
* `FIX` [#1943]
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index 9c68e648..5c63387a 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -316,6 +316,27 @@ vm.binarySwitch = util.switch()
return
end
end
+ if op == '/'
+ or op == '^' then
+ local uri = guide.getUri(source)
+ local infer1 = vm.getInfer(source[1])
+ local infer2 = vm.getInfer(source[2])
+ if (infer1:hasType(uri, 'integer') or infer1:hasType(uri, 'number'))
+ and (infer2:hasType(uri, 'integer') or infer2:hasType(uri, 'number')) then
+ vm.setNode(source, vm.declareGlobal('type', 'number'))
+ return
+ end
+ end
+ if op == '//' then
+ local uri = guide.getUri(source)
+ local infer1 = vm.getInfer(source[1])
+ local infer2 = vm.getInfer(source[2])
+ if (infer1:hasType(uri, 'integer') or infer1:hasType(uri, 'number'))
+ and (infer2:hasType(uri, 'integer') or infer2:hasType(uri, 'number')) then
+ vm.setNode(source, vm.declareGlobal('type', 'integer'))
+ return
+ end
+ end
end
end)
: case '..'
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index bc70fbf4..13585790 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -4254,3 +4254,10 @@ local fooOrBar
local <?b?> = foo * fooOrBar
]]
+
+TEST 'number' [[
+local a = 4;
+local b = 2;
+
+local <?c?> = a / b;
+]]