diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/core/diagnostics/global-in-nil-env.lua | 3 | ||||
-rw-r--r-- | script/parser/guide.lua | 13 | ||||
-rw-r--r-- | test/diagnostics/common.lua | 6 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 33 |
5 files changed, 56 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index a562d717..9dfff867 100644 --- a/changelog.md +++ b/changelog.md @@ -1,9 +1,11 @@ # changelog ## 3.6.14 +* `FIX` [#1715] * `FIX` [#1753] * `FIX` [#1914] +[#1715]: https://github.com/LuaLS/lua-language-server/issues/1715 [#1753]: https://github.com/LuaLS/lua-language-server/issues/1753 [#1914]: https://github.com/LuaLS/lua-language-server/issues/1914 diff --git a/script/core/diagnostics/global-in-nil-env.lua b/script/core/diagnostics/global-in-nil-env.lua index e154080c..daf1f99d 100644 --- a/script/core/diagnostics/global-in-nil-env.lua +++ b/script/core/diagnostics/global-in-nil-env.lua @@ -13,6 +13,9 @@ return function (uri, callback) if node.tag == '_ENV' then return end + if guide.isParam(node) then + return + end if not node.value or node.value.type == 'nil' then callback { diff --git a/script/parser/guide.lua b/script/parser/guide.lua index ec5746c1..e7eb3751 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1276,4 +1276,17 @@ function m.getTopBlock(source) return nil end +---@param source parser.object +---@return boolean +function m.isParam(source) + if source.type ~= 'local' + and source.type ~= 'self' then + return false + end + if source.parent.type ~= 'funcargs' then + return false + end + return true +end + return m diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 89537771..a1dbe819 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -2262,3 +2262,9 @@ else function X.f() end end ]] + +TESTWITH 'global-in-nil-env' [[ +local function foo(_ENV) + Joe = "human" +end +]] diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 3c19e58d..827d4d08 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -27,7 +27,7 @@ local function founded(targets, results) end ---@diagnostic disable: await-in-sync -function TEST(script, ...) +function TEST(script) local newScript, catched = catch(script, '!') files.setText(TESTURI, newScript) files.open(TESTURI) @@ -53,5 +53,36 @@ function TEST(script, ...) end end +function TESTWITH(code) + return function (script) + local newScript, catched = catch(script, '!') + files.setText(TESTURI, newScript) + files.open(TESTURI) + local origins = {} + local results = {} + core(TESTURI, false, function (result) + if code ~= result.code then + return + end + results[#results+1] = { result.start, result.finish } + origins[#origins+1] = result + end) + + if results[1] then + if not founded(catched['!'] or {}, results) then + error(('%s\n%s'):format(util.dump(catched['!']), util.dump(results))) + end + else + assert(#catched['!'] == 0) + end + + files.remove(TESTURI) + + return function (callback) + callback(origins) + end + end +end + require 'diagnostics.common' require 'diagnostics.type-check' |