summaryrefslogtreecommitdiff
path: root/script/core/diagnostics
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-18 01:58:48 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-18 01:58:48 +0800
commit53d376ce281906fd856fac42073a072906b2628e (patch)
treed72c05a6100b9f8da4650106653a85ec2a55c044 /script/core/diagnostics
parentbc4e205a4953a7f3a99bafc9fc88295f929beab1 (diff)
downloadlua-language-server-53d376ce281906fd856fac42073a072906b2628e.zip
update
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r--script/core/diagnostics/assign-type-mismatch.lua20
-rw-r--r--script/core/diagnostics/cast-local-type.lua41
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