summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/cast-field-type.lua77
-rw-r--r--script/core/diagnostics/init.lua1
-rw-r--r--script/proto/define.lua2
-rw-r--r--script/vm/compiler.lua16
4 files changed, 6 insertions, 90 deletions
diff --git a/script/core/diagnostics/cast-field-type.lua b/script/core/diagnostics/cast-field-type.lua
deleted file mode 100644
index 5cf36a5a..00000000
--- a/script/core/diagnostics/cast-field-type.lua
+++ /dev/null
@@ -1,77 +0,0 @@
-local files = require 'files'
-local lang = require 'language'
-local guide = require 'parser.guide'
-local vm = require 'vm'
-local await = require 'await'
-
----@async
-return function (uri, callback)
- do return end
- if not PREVIEW and not TEST then
- return
- end
- local state = files.getState(uri)
- if not state then
- return
- end
-
- local fieldNodeCache = {}
-
- local function getParentField(parent, key)
- if parent.type == 'getlocal' then
- parent = parent.node
- end
- if not fieldNodeCache[parent] then
- fieldNodeCache[parent] = {}
- end
- if fieldNodeCache[parent][key] then
- return fieldNodeCache[parent][key]
- end
- local fieldNode = vm.createNode()
- fieldNodeCache[parent][key] = fieldNode
- for _, class in ipairs(vm.getDefs(parent)) do
- if class.type == 'doc.class' then
- vm.getClassFields(uri, vm.getGlobal('type', class.class[1]), key, false, function (def)
- if def.type == 'doc.field'
- or def.type == 'setfield'
- or def.type == 'setmethod'
- or def.type == 'setindex' then
- fieldNode:merge(vm.compileNode(def))
- end
- end)
- end
- end
- return fieldNode
- end
-
- ---@async
- guide.eachSourceTypes(state.ast, { 'setfield', 'setindex', 'setmethod', 'tablefield', 'tableindex' }, function (ref)
- await.delay()
- if not ref.value then
- return
- end
- local key = guide.getKeyName(ref)
- if not key then
- return nil
- end
- if not vm.canCastType(uri, vm.compileNode(ref), vm.compileNode(ref.value)) then
- return
- end
- local parent = ref.node
- local fieldNode = getParentField(parent, key)
- if not fieldNode or fieldNode:isEmpty() then
- return
- end
- if vm.canCastType(uri, fieldNode, vm.compileNode(ref.value)) then
- return
- end
- callback {
- start = ref.start,
- finish = ref.finish,
- message = lang.script('DIAG_CAST_FIELD_TYPE', {
- def = vm.getInfer(fieldNode):view(uri),
- ref = vm.getInfer(ref.value):view(uri),
- }),
- }
- end)
-end
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index efd23bf4..fe551bc8 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -13,7 +13,6 @@ local diagSort = {
['undefined-field'] = 110,
['redundant-parameter'] = 110,
['cast-local-type'] = 120,
- ['cast-field-type'] = 120,
['assign-type-mismatch'] = 120,
}
diff --git a/script/proto/define.lua b/script/proto/define.lua
index d748c5a2..8c7c7a0f 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -50,7 +50,6 @@ m.DiagnosticDefaultSeverity = {
['discard-returns'] = 'Warning',
['need-check-nil'] = 'Warning',
['cast-local-type'] = 'Warning',
- ['cast-field-type'] = 'Warning',
['assign-type-mismatch'] = 'Warning',
['duplicate-doc-alias'] = 'Warning',
@@ -114,7 +113,6 @@ m.DiagnosticDefaultNeededFileStatus = {
['discard-returns'] = 'Opened',
['need-check-nil'] = 'Opened',
['cast-local-type'] = 'Any',
- ['cast-field-type'] = 'Any',
['assign-type-mismatch'] = 'Any',
['duplicate-doc-alias'] = 'Any',
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 51999266..165dc6fb 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1368,24 +1368,20 @@ local compilerSwitch = util.switch()
hasMarkDoc = bindDocs(source)
end
- if source.value then
- if not hasMarkDoc or guide.isLiteral(source.value) then
- if source.value.type == 'table' then
- vm.setNode(source, source.value)
- else
- vm.setNode(source, vm.compileNode(source.value))
- end
- end
- end
-
if not hasMarkDoc then
vm.compileByParentNode(source.node, guide.getKeyName(source), false, function (src)
if src.type == 'doc.field'
or src.type == 'doc.type.field' then
+ hasMarkDoc = true
vm.setNode(source, vm.compileNode(src))
end
end)
end
+
+ if not hasMarkDoc and source.value then
+ vm.setNode(source, vm.compileNode(source.value))
+ end
+
end)
: case 'field'
: case 'method'