diff options
-rw-r--r-- | server/src/core/diagnostics.lua | 32 | ||||
-rw-r--r-- | server/test/diagnostics/init.lua | 7 |
2 files changed, 18 insertions, 21 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index ff030348..84d3578c 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -44,13 +44,6 @@ function mt:searchUndefinedGlobal(callback) for name in pairs(config.config.diagnostics.globals) do definedGlobal[name] = true end - local envValue = self.vm.env:getValue() - envValue:eachInfo(function (info) - if info.type == 'set child' then - local name = info[1] - definedGlobal[name] = true - end - end) self.vm:eachSource(function (source) if not source:get 'global' then return @@ -63,23 +56,22 @@ function mt:searchUndefinedGlobal(callback) if not value then return end - if not value:isGlobal() then - -- 上文重载了 _ENV 的情况 - local ok = value:eachInfo(function (info) - if info.type == 'set' then - return true - end - end) - if ok then - return - end - callback(source.start, source.finish, name) + if definedGlobal[name] then return end - if definedGlobal[name] then + local parent = source:get 'parent' + if not parent then return end - if type(name) ~= 'string' then + local ok = parent:eachInfo(function (info, src) + if info.type == 'set child' and info[1] == name then + return true + end + if src == source then + return false + end + end) + if ok then return end callback(source.start, source.finish, name) diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua index 7bba139d..a6dc6d93 100644 --- a/server/test/diagnostics/init.lua +++ b/server/test/diagnostics/init.lua @@ -72,7 +72,7 @@ print(<!X!>) print(<!Log!>) print(_VERSION) print(<!y!>) -print(Z) +print(<!Z!>) Z = 1 ]] @@ -119,6 +119,11 @@ local _ENV ]] TEST [[ +print(1) +_ENV = nil +]] + +TEST [[ print() <!('string')!>:sub(1, 1) ]] |