From 53d376ce281906fd856fac42073a072906b2628e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 18 Jun 2022 01:58:48 +0800 Subject: update --- script/core/diagnostics/assign-type-mismatch.lua | 20 ++++++------ script/core/diagnostics/cast-local-type.lua | 41 ++++++------------------ 2 files changed, 19 insertions(+), 42 deletions(-) (limited to 'script/core') diff --git a/script/core/diagnostics/assign-type-mismatch.lua b/script/core/diagnostics/assign-type-mismatch.lua index d301faed..168106a6 100644 --- a/script/core/diagnostics/assign-type-mismatch.lua +++ b/script/core/diagnostics/assign-type-mismatch.lua @@ -36,18 +36,16 @@ return function (uri, callback) end local varNode = vm.compileNode(source) local valueNode = vm.compileNode(value) - if vm.getInfer(varNode):hasUnknown(uri) then + if vm.canCastType(uri, varNode, valueNode) then return end - if not vm.isSubType(uri, valueNode, varNode) then - callback { - start = source.start, - finish = source.finish, - message = lang.script('DIAG_ASSIGN_TYPE_MISMATCH', { - loc = vm.getInfer(varNode):view(uri), - ref = vm.getInfer(valueNode):view(uri), - }), - } - end + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_ASSIGN_TYPE_MISMATCH', { + loc = vm.getInfer(varNode):view(uri), + ref = vm.getInfer(valueNode):view(uri), + }), + } end) end diff --git a/script/core/diagnostics/cast-local-type.lua b/script/core/diagnostics/cast-local-type.lua index 65cc0368..ea14ffb6 100644 --- a/script/core/diagnostics/cast-local-type.lua +++ b/script/core/diagnostics/cast-local-type.lua @@ -21,43 +21,22 @@ return function (uri, callback) if not locNode:getData 'hasDefined' then return end - if vm.getInfer(loc):hasUnknown(uri) then - return - end - - -- allow `local x = {};x = nil`, - -- but not allow `local x ---@type table;x = nil` - local allowNil = vm.getInfer(loc):hasType(uri, 'table') - and not locNode:hasType 'table' - - -- allow `local x = 0;x = 1.0`, - -- but not allow `local x ---@type integer;x = 1.0` - local allowNumber = vm.getInfer(loc):hasType(uri, 'integer') - and not locNode:hasType 'integer' - for _, ref in ipairs(loc.ref) do if ref.type == 'setlocal' then await.delay() local refNode = vm.compileNode(ref) - if allowNil and vm.isSubType(uri, refNode, 'nil') then - goto CONTINUE - end - if allowNumber and vm.isSubType(uri, refNode, 'number') then - goto CONTINUE - end - if vm.isSubType(uri, refNode, locNode) then - goto CONTINUE + + if not vm.canCastType(uri, locNode, refNode) then + callback { + start = ref.start, + finish = ref.finish, + message = lang.script('DIAG_CAST_LOCAL_TYPE', { + loc = vm.getInfer(locNode):view(uri), + ref = vm.getInfer(refNode):view(uri), + }), + } end - callback { - start = ref.start, - finish = ref.finish, - message = lang.script('DIAG_CAST_LOCAL_TYPE', { - loc = vm.getInfer(locNode):view(uri), - ref = vm.getInfer(refNode):view(uri), - }), - } end - ::CONTINUE:: end end) end -- cgit v1.2.3