From 4399ca74c753c8822a62a2174ab2f47cefe98dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 27 Mar 2023 16:46:50 +0800 Subject: check operator `/`, `^` and `//` fix #2036 --- changelog.md | 5 +++++ script/vm/operator.lua | 21 +++++++++++++++++++++ test/type_inference/init.lua | 7 +++++++ 3 files changed, 33 insertions(+) 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 = foo * fooOrBar ]] + +TEST 'number' [[ +local a = 4; +local b = 2; + +local = a / b; +]] -- cgit v1.2.3