diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-10-27 20:37:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-10-27 20:37:20 +0800 |
commit | b19c7cefcaeac4537054be2dab6f7cf4b3d7ed26 (patch) | |
tree | 5eab7e925b74b41d7567c5341f05f78145ad2d0c | |
parent | b6f384e930448d5259ec100117bd752802c21c7c (diff) | |
download | lua-language-server-b19c7cefcaeac4537054be2dab6f7cf4b3d7ed26.zip |
fix type-check
assign object to `nil`
-rw-r--r-- | script/vm/type.lua | 3 | ||||
-rw-r--r-- | test/diagnostics/type-check.lua | 17 |
2 files changed, 11 insertions, 9 deletions
diff --git a/script/vm/type.lua b/script/vm/type.lua index 15504878..f2870d28 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -433,6 +433,9 @@ function vm.canCastType(uri, defNode, refNode) if refInfer:view(uri) == 'unknown' then return true end + if defInfer:view(uri) == 'nil' then + return true + end if vm.isSubType(uri, refNode, 'nil') then -- allow `local x = {};x = nil`, diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 746d4669..6455cd66 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -855,15 +855,14 @@ function MyClass:new() end ]] --- TODO ---TEST [[ ------@class T ---local t = { --- x = nil ---} --- ---t.x = 1 ---]] +TEST [[ +---@class T +local t = { + x = nil +} + +t.x = 1 +]] config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'unused-function') |