diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-05 14:50:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-05 14:50:16 +0800 |
commit | 60189b2603798bba46e0c0aefdbad575efebfcee (patch) | |
tree | 1a8894c7d32177428dcb268ab4bf3150d9e8eee6 | |
parent | d086077b0ecd351319504f3e0fcef9912c4fedb4 (diff) | |
download | lua-language-server-60189b2603798bba46e0c0aefdbad575efebfcee.zip |
fix #1267
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/vm/compiler.lua | 3 | ||||
-rw-r--r-- | script/vm/node.lua | 27 | ||||
-rw-r--r-- | test/type_inference/init.lua | 7 |
4 files changed, 37 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 1b47c102..451a1b96 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ * `type.weakNilCheck` * `FIX` [#1256](https://github.com/sumneko/lua-language-server/issues/1256) * `FIX` [#1257](https://github.com/sumneko/lua-language-server/issues/1257) +* `FIX` [#1267](https://github.com/sumneko/lua-language-server/issues/1267) * `FIX` [#1269](https://github.com/sumneko/lua-language-server/issues/1269) * `FIX` [#1273](https://github.com/sumneko/lua-language-server/issues/1273) * `FIX` [#1275](https://github.com/sumneko/lua-language-server/issues/1275) diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index e361d706..1936fc75 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1309,7 +1309,8 @@ local compilerSwitch = util.switch() end if src.value then if src.value.type == 'table' then - vm.setNode(src, vm.createNode(src.value), true) + vm.setNode(src, vm.createNode(src.value)) + vm.setNode(src, node:copy():asTable()) else vm.setNode(src, vm.compileNode(src.value), true) end diff --git a/script/vm/node.lua b/script/vm/node.lua index 45e5e6c4..f0d0b0ba 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -227,6 +227,7 @@ function mt:remove(name) or (c.type == 'doc.type.boolean' and name == 'false' and c[1] == false) or (c.type == 'doc.type.table' and name == 'table') or (c.type == 'doc.type.array' and name == 'table') + or (c.type == 'doc.type.sign' and name == 'table') or (c.type == 'doc.type.function' and name == 'function') then table.remove(self, index) self[c] = nil @@ -247,6 +248,7 @@ function mt:narrow(name) or (c.type == 'doc.type.boolean' and name == 'boolean') or (c.type == 'doc.type.table' and name == 'table') or (c.type == 'doc.type.array' and name == 'table') + or (c.type == 'doc.type.sign' and name == 'table') or (c.type == 'doc.type.function' and name == 'function') then goto CONTINUE end @@ -328,6 +330,31 @@ function mt:hasName(name) return false end +---@return vm.node +function mt:asTable() + self.optional = nil + for index = #self, 1, -1 do + local c = self[index] + if c.type == 'table' + or c.type == 'doc.type.table' + or c.type == 'doc.type.array' + or c.type == 'doc.type.sign' then + goto CONTINUE + end + if c.type == 'global' and c.cate == 'type' then + ---@cast c vm.global + if c.name == 'table' + or not guide.isBasicType(c.name) then + goto CONTINUE + end + end + table.remove(self, index) + self[c] = nil + ::CONTINUE:: + end + return self +end + ---@return fun():vm.node.object function mt:eachObject() local i = 0 diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index e2b42369..7fa6ec7c 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3350,3 +3350,10 @@ local s local test = t[n] local <?test2?> = t[s] --test and test2 are unknow ]] + +TEST 'table<number, boolean>' [[ +---@type table<number, boolean> +local t + +<?t?> = {} +]] |