From 90b95a06eb43b469f53c147509a4d67e1c567fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 11 Aug 2023 18:24:34 +0800 Subject: [PATCH] local uses `nil` at least fix #2155 --- changelog.md | 2 ++ script/vm/compiler.lua | 6 ++++++ test/type_inference/init.lua | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/changelog.md b/changelog.md index 8cbfc1d24..a39f505d0 100644 --- a/changelog.md +++ b/changelog.md @@ -3,8 +3,10 @@ ## 3.7.0 * `NEW` support `---@type` and `--[[@as]]` for return statement * `FIX` wrong hover and signature for method with varargs and overloads +* `FIX` [#2155] * `FIX` [#2224] +[#2155]: https://github.com/LuaLS/lua-language-server/issues/2155 [#2224]: https://github.com/LuaLS/lua-language-server/issues/2224 ## 3.6.25 diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 7faa4f473..7d10561eb 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1112,6 +1112,12 @@ local function compileLocal(source) end end + if source.value + and source.value.type == 'nil' + and not myNode:hasKnownType() then + vm.setNode(source, vm.compileNode(source.value)) + end + myNode.hasDefined = hasMarkDoc or hasMarkParam or hasMarkValue end diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index aba6b0b4f..98a07ca3f 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -44,6 +44,10 @@ function TEST(wanted) end end +TEST 'nil' [[ +local = nil +]] + TEST 'string' [[ local = '111' ]]