diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/assign-type-mismatch.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/duplicate-set-field.lua | 8 | ||||
-rw-r--r-- | script/core/diagnostics/return-type-mismatch.lua | 6 | ||||
-rw-r--r-- | script/core/diagnostics/unused-function.lua | 5 |
4 files changed, 15 insertions, 6 deletions
diff --git a/script/core/diagnostics/assign-type-mismatch.lua b/script/core/diagnostics/assign-type-mismatch.lua index e84e41df..536cfaff 100644 --- a/script/core/diagnostics/assign-type-mismatch.lua +++ b/script/core/diagnostics/assign-type-mismatch.lua @@ -36,7 +36,7 @@ return function (uri, callback) end end local valueNode = vm.compileNode(value) - if source.type == 'setindex' then + if source.type == 'setindex' then -- boolean[1] = nil valueNode = valueNode:copy():removeOptional() end diff --git a/script/core/diagnostics/duplicate-set-field.lua b/script/core/diagnostics/duplicate-set-field.lua index 8052c420..f5007eb1 100644 --- a/script/core/diagnostics/duplicate-set-field.lua +++ b/script/core/diagnostics/duplicate-set-field.lua @@ -48,10 +48,12 @@ return function (uri, callback) local blocks = {} for _, value in ipairs(values) do local block = guide.getBlock(value) - if not blocks[block] then - blocks[block] = {} + if block then + if not blocks[block] then + blocks[block] = {} + end + blocks[block][#blocks[block]+1] = value end - blocks[block][#blocks[block]+1] = value end for _, defs in pairs(blocks) do if #defs <= 1 then diff --git a/script/core/diagnostics/return-type-mismatch.lua b/script/core/diagnostics/return-type-mismatch.lua index ba23fa2c..c170679f 100644 --- a/script/core/diagnostics/return-type-mismatch.lua +++ b/script/core/diagnostics/return-type-mismatch.lua @@ -38,6 +38,12 @@ return function (uri, callback) if not exp then break end + if retNode:hasName 'nil' then + if exp.type == 'getfield' + or exp.type == 'getindex' then + retNode = retNode:copy():removeOptional() + end + end if not vm.canCastType(uri, docRet, retNode) then callback { start = exp.start, diff --git a/script/core/diagnostics/unused-function.lua b/script/core/diagnostics/unused-function.lua index 813ac804..a873375f 100644 --- a/script/core/diagnostics/unused-function.lua +++ b/script/core/diagnostics/unused-function.lua @@ -18,7 +18,8 @@ local function isToBeClosed(source) return false end ----@param source parser.object +---@param source parser.object? +---@return boolean local function isValidFunction(source) if not source then return false @@ -55,7 +56,7 @@ local function collect(ast, white, roots, links) for _, ref in ipairs(loc.ref or {}) do if ref.type == 'getlocal' then local func = guide.getParentFunction(ref) - if not isValidFunction(func) or roots[func] then + if not func or not isValidFunction(func) or roots[func] then roots[src] = true return end |