diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/config/config.lua | 2 | ||||
-rw-r--r-- | script/core/code-action.lua | 4 | ||||
-rw-r--r-- | script/provider/markdown.lua | 1 | ||||
-rw-r--r-- | script/vm/compiler.lua | 24 | ||||
-rw-r--r-- | script/vm/node.lua | 9 | ||||
-rw-r--r-- | script/vm/type.lua | 10 |
6 files changed, 39 insertions, 11 deletions
diff --git a/script/config/config.lua b/script/config/config.lua index 73d21b0b..df998990 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -164,7 +164,7 @@ function m.prop(uri, key, prop, value) return false end ----@param uri uri +---@param uri? uri ---@param key string ---@return any function m.get(uri, key) diff --git a/script/core/code-action.lua b/script/core/code-action.lua index 116fff24..d2cf440a 100644 --- a/script/core/code-action.lua +++ b/script/core/code-action.lua @@ -5,6 +5,10 @@ local sp = require 'bee.subprocess' local guide = require "parser.guide" local converter = require 'proto.converter' +---@param uri uri +---@param row integer +---@param mode string +---@param code string local function checkDisableByLuaDocExits(uri, row, mode, code) if row < 0 then return nil diff --git a/script/provider/markdown.lua b/script/provider/markdown.lua index 653ae135..6b007713 100644 --- a/script/provider/markdown.lua +++ b/script/provider/markdown.lua @@ -48,6 +48,7 @@ function mt:emptyLine() return self end +---@return string function mt:string(nl) if self._cacheResult then return self._cacheResult diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 795113e0..2f3cc36f 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1105,7 +1105,7 @@ local binarySwich = util.switch() start = source.start, finish = source.finish, parent = source, - [1] =result, + [1] = result, }) else vm.setNode(source, vm.declareGlobal('type', 'integer')) @@ -1140,7 +1140,7 @@ local binarySwich = util.switch() start = source.start, finish = source.finish, parent = source, - [1] =result, + [1] = result, }) else if op == '+' @@ -1149,10 +1149,15 @@ local binarySwich = util.switch() or op == '//' or op == '%' then local uri = guide.getUri(source) - if vm.getInfer(source[1]):view(uri) == 'integer' - and vm.getInfer(source[2]):view(uri) == 'integer' then - vm.setNode(source, vm.declareGlobal('type', 'integer')) - return + local infer1 = vm.getInfer(source[1]) + local infer2 = vm.getInfer(source[2]) + if infer1:hasType(uri, 'integer') + or infer2:hasType(uri, 'integer') then + if not infer1:hasType(uri, 'number') + and not infer2:hasType(uri, 'number') then + vm.setNode(source, vm.declareGlobal('type', 'integer')) + return + end end end vm.setNode(source, vm.declareGlobal('type', 'number')) @@ -1736,7 +1741,12 @@ local compilerSwitch = util.switch() if source.op.type == '-' then local v = vm.getNumber(source[1]) if v == nil then - vm.setNode(source, vm.declareGlobal('type', 'number')) + local infer = vm.getInfer(source[1]) + if infer:hasType(guide.getUri(source), 'integer') then + vm.setNode(source, vm.declareGlobal('type', 'integer')) + else + vm.setNode(source, vm.declareGlobal('type', 'number')) + end return else vm.setNode(source, { diff --git a/script/vm/node.lua b/script/vm/node.lua index 61781e5f..8ed5c027 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -310,6 +310,7 @@ end ---@param source vm.object ---@param node vm.node | vm.object ---@param cover? boolean +---@return vm.node function vm.setNode(source, node, cover) if not node then if TEST then @@ -324,18 +325,20 @@ function vm.setNode(source, node, cover) if cover then ---@cast node vm.node vm.nodeCache[source] = node - return + return node end local me = vm.nodeCache[source] if me then me:merge(node) else if node.type == 'vm.node' then - vm.nodeCache[source] = node:copy() + me = node:copy() else - vm.nodeCache[source] = vm.createNode(node) + me = vm.createNode(node) end + vm.nodeCache[source] = me end + return me end ---@param source vm.object diff --git a/script/vm/type.lua b/script/vm/type.lua index 8e8ca96b..5735b482 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -250,6 +250,16 @@ function vm.canCastType(uri, defNode, refNode) return true end end + + if vm.isSubType(uri, refNode, 'number') then + -- allow `local x = 0;x = 1.0`, + -- but not allow `local x ---@type integer;x = 1.0` + if defInfer:hasType(uri, 'integer') + and not defNode:hasType 'integer' then + return true + end + end + if vm.isSubType(uri, refNode, defNode) then return true end |