From a212b62603f6087bc5a34c4aea45f7cdb0643a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Jun 2022 17:07:02 +0800 Subject: update --- script/vm/function.lua | 2 +- script/vm/infer.lua | 6 ++++++ script/vm/type.lua | 6 ++++-- test/diagnostics/type-check.lua | 8 ++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/script/vm/function.lua b/script/vm/function.lua index 45f8c0df..2a169bd6 100644 --- a/script/vm/function.lua +++ b/script/vm/function.lua @@ -117,7 +117,7 @@ function vm.countReturnsOfFunction(func) max = dmax end end - return min, max + return min or 0, max or math.huge end if func.type == 'doc.type.function' then return vm.countList(func.returns) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index f7ff2569..35a2f59f 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -270,6 +270,12 @@ function mt:hasUnknown(uri) or self.views['unknown'] == true end +---@param uri uri +function mt:hasAny(uri) + self:_computeViews(uri) + return self.views['any'] == true +end + ---@param uri uri ---@return boolean function mt:hasClass(uri) diff --git a/script/vm/type.lua b/script/vm/type.lua index 5735b482..fa78f735 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -235,10 +235,12 @@ function vm.canCastType(uri, defNode, refNode) local defInfer = vm.getInfer(defNode) local refInfer = vm.getInfer(refNode) - if defInfer:hasUnknown(uri) then + if defInfer:hasUnknown(uri) + or defInfer:hasAny(uri) then return true end - if refInfer:hasUnknown(uri) then + if refInfer:hasUnknown(uri) + or refInfer:hasAny(uri) then return true end diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index bb0ccdc0..46997181 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -332,5 +332,13 @@ local x x = 1 + G ]] +TEST [[ +---@diagnostic disable:undefined-global +---@type integer +local x + +x = 1 + G +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') -- cgit v1.2.3