diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-18 01:58:48 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-18 01:58:48 +0800 |
commit | 53d376ce281906fd856fac42073a072906b2628e (patch) | |
tree | d72c05a6100b9f8da4650106653a85ec2a55c044 /script/core/diagnostics | |
parent | bc4e205a4953a7f3a99bafc9fc88295f929beab1 (diff) | |
download | lua-language-server-53d376ce281906fd856fac42073a072906b2628e.zip |
update
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r-- | script/core/diagnostics/assign-type-mismatch.lua | 20 | ||||
-rw-r--r-- | script/core/diagnostics/cast-local-type.lua | 41 |
2 files changed, 19 insertions, 42 deletions
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 |