From 7221cc92acd0099ed28727536c30d264b3cb7bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 20 Jun 2022 23:26:07 +0800 Subject: resolve #1211 --- script/vm/compiler.lua | 31 +++++++++++++++++++------------ test/diagnostics/type-check.lua | 9 +++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 165dc6fb..fade0a78 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -306,7 +306,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult) if vm.isSubType(suri, typeName, fieldNode) then local nkey = '|' .. typeName if not searchedFields[nkey] then - pushResult(field) + pushResult(field, true) hasFounded[nkey] = true end end @@ -317,16 +317,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult) -- check local field and global field if not hasFounded[key] and set.bindSources then for _, src in ipairs(set.bindSources) do - searchFieldSwitch(src.type, suri, src, key, ref, function (field) - local fieldKey = guide.getKeyName(field) - if fieldKey then - if not searchedFields[fieldKey] - and guide.isSet(field) then - hasFounded[fieldKey] = true - pushResult(field) - end - end - end) + local skipSetLocal if src.value and src.value.type == 'table' then searchFieldSwitch('table', suri, src.value, key, ref, function (field) local fieldKey = guide.getKeyName(field) @@ -334,7 +325,22 @@ function vm.getClassFields(suri, object, key, ref, pushResult) if not searchedFields[fieldKey] and guide.isSet(field) then hasFounded[fieldKey] = true - pushResult(field) + pushResult(field, true) + if src.type == 'local' then + skipSetLocal = true + end + end + end + end) + end + if not skipSetLocal then + searchFieldSwitch(src.type, suri, src, key, ref, function (field) + local fieldKey = guide.getKeyName(field) + if fieldKey then + if not searchedFields[fieldKey] + and guide.isSet(field) then + hasFounded[fieldKey] = true + pushResult(field, true) end end end) @@ -647,6 +653,7 @@ function vm.compileByParentNode(source, key, ref, pushResult) and node.cate == 'type' and not guide.isBasicType(node.name) then hasClass = true + break end end for node in parentNode:eachObject() do diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index ace503ad..9dda3333 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -274,5 +274,14 @@ local t = { true } t[1] = nil ]] +TEST [[ +---@class A +local t = { + x = 1 +} + + = true +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') -- cgit v1.2.3