diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-22 16:29:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-22 16:29:18 +0800 |
commit | 09512074acae34fccc60f31a8c84d022e03ddf23 (patch) | |
tree | d431ad47d4688b6b879686a1c4926235ac3afa01 | |
parent | e5d692cb0845e5de7988904017440bd4db551bb7 (diff) | |
download | lua-language-server-09512074acae34fccc60f31a8c84d022e03ddf23.zip |
update
-rw-r--r-- | meta/template/io.lua | 9 | ||||
-rw-r--r-- | meta/template/string.lua | 4 | ||||
-rw-r--r-- | script/client.lua | 2 | ||||
-rw-r--r-- | script/config/config.lua | 4 | ||||
-rw-r--r-- | script/vm/type.lua | 21 | ||||
-rw-r--r-- | test/diagnostics/type-check.lua | 21 |
6 files changed, 37 insertions, 24 deletions
diff --git a/meta/template/io.lua b/meta/template/io.lua index b1fe5a9e..3a6e37ff 100644 --- a/meta/template/io.lua +++ b/meta/template/io.lua @@ -42,7 +42,7 @@ function io.input(file) end ---#DES 'io.lines' ---@param filename string? ---@param ... readmode ----@return fun():string|number +---@return fun():any, ... function io.lines(filename, ...) end ---#DES 'io.open' @@ -71,7 +71,7 @@ function io.popen(prog, mode) end ---#DES 'io.read' ---@param ... readmode ----@return string|number +---@return any ---@return ... ---@nodiscard function io.read(...) end @@ -129,12 +129,13 @@ function file:flush() end ---#DES 'file:lines' ---@param ... readmode ----@return fun():string|number +---@return fun():any, ... function file:lines(...) end ---#DES 'file:read' ---@param ... readmode ----@return string|number +---@return any +---@return ... ---@nodiscard function file:read(...) end diff --git a/meta/template/string.lua b/meta/template/string.lua index 8f0790d6..f74f7546 100644 --- a/meta/template/string.lua +++ b/meta/template/string.lua @@ -40,8 +40,8 @@ function string.dump(f, strip) end function string.find(s, pattern, init, plain) end ---#DES 'string.format' ----@param s string ----@param ... string +---@param s any +---@param ... any ---@return string ---@nodiscard function string.format(s, ...) end diff --git a/script/client.lua b/script/client.lua index 2ce29803..f0f7aa44 100644 --- a/script/client.lua +++ b/script/client.lua @@ -112,7 +112,7 @@ end ---@param type message.type ---@param message string ---@param titles string[] ----@param callback fun(action: string, index: integer) +---@param callback fun(action?: string, index?: integer) function m.requestMessage(type, message, titles, callback) proto.notify('window/logMessage', { type = define.MessageType[type] or 3, diff --git a/script/config/config.lua b/script/config/config.lua index f8d9e985..73d21b0b 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -27,7 +27,7 @@ local function update(scp, key, nowValue, rawValue) raw[key] = rawValue end ----@param uri uri +---@param uri? uri ---@param key? string ---@return scope local function getScope(uri, key) @@ -70,7 +70,7 @@ function m.setByScope(scp, key, value) return true end ----@param uri uri +---@param uri? uri ---@param key string ---@param value any function m.set(uri, key, value) diff --git a/script/vm/type.lua b/script/vm/type.lua index ecca4382..8e8ca96b 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -95,6 +95,19 @@ function vm.isSubType(uri, child, parent, mark) return true end + if parentName == 'integer' and childName == 'number' then + if child.type == 'number' + and child[1] + and not math.tointeger(child[1]) then + return false + end + if child.type == 'global' + and child.cate == 'type' then + return false + end + return true + end + -- TODO: check duck if parentName == 'table' and not guide.isBasicType(childName) then return true @@ -237,14 +250,6 @@ 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 diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 3e4584c0..b9681d78 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -153,13 +153,6 @@ x = 1.0 ]] TEST [[ ----@type integer -local x = 0 - -<!x!> = 1.0 -]] - -TEST [[ ---@class A local t = {} @@ -317,5 +310,19 @@ local function f(x) end f(<!true!>) ]] +TEST [[ +---@type integer +local x + +x = 1.0 +]] + +TEST [[ +---@type integer +local x + +<!x!> = 1.5 +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') |