From 23411c384b049f015d4f7d80409125894a9e2d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 17 Sep 2019 10:58:44 +0800 Subject: =?UTF-8?q?=5FENV=E7=BD=AE=E4=B8=BAnil=E5=90=8E=E7=9A=84=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E5=8F=98=E9=87=8F=E8=AF=8A=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/diagnostics.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'server/src/core') diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 509fe48c..0e0d85ba 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -553,6 +553,29 @@ function mt:searchUndefinedEnvChild(callback) end) end +function mt:searchGlobalInNilEnv(callback) + self.vm:eachSource(function (source) + if not source:get 'global' then + return + end + local name = source:getName() + if name == '' then + return + end + local parentSource = source:get 'parent' :getSource() + if parentSource.type == 'nil' then + callback(source.start, source.finish, { + { + start = parentSource.start, + finish = parentSource.finish, + uri = self.uri, + } + }) + end + return + end) +end + function mt:checkEmmyClass(source, callback) local class = source:get 'emmy.class' if not class then @@ -919,6 +942,20 @@ return function (vm, lines, uri) } end end) + -- 全局变量不可用(置空了 `_ENV`) + session:doDiagnostics(session.searchGlobalInNilEnv, 'global-in-nil-env', function (related) + if vm.envType == '_ENV' then + return { + message = lang.script.DIAG_GLOBAL_IN_NIL_ENV, + related = related, + } + else + return { + message = lang.script.DIAG_GLOBAL_IN_NIL_FENV, + related = related, + } + end + end) -- 构建表时重复定义field session:doDiagnostics(session.searchDuplicateIndex, 'duplicate-index', function (key, related, type) if type == 'unused' then -- cgit v1.2.3