Skip to content

Commit 60189b2

Browse files
committed
fix #1267
1 parent d086077 commit 60189b2

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* `type.weakNilCheck`
66
* `FIX` [#1256](https://github.com/sumneko/lua-language-server/issues/1256)
77
* `FIX` [#1257](https://github.com/sumneko/lua-language-server/issues/1257)
8+
* `FIX` [#1267](https://github.com/sumneko/lua-language-server/issues/1267)
89
* `FIX` [#1269](https://github.com/sumneko/lua-language-server/issues/1269)
910
* `FIX` [#1273](https://github.com/sumneko/lua-language-server/issues/1273)
1011
* `FIX` [#1275](https://github.com/sumneko/lua-language-server/issues/1275)

script/vm/compiler.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,8 @@ local compilerSwitch = util.switch()
13091309
end
13101310
if src.value then
13111311
if src.value.type == 'table' then
1312-
vm.setNode(src, vm.createNode(src.value), true)
1312+
vm.setNode(src, vm.createNode(src.value))
1313+
vm.setNode(src, node:copy():asTable())
13131314
else
13141315
vm.setNode(src, vm.compileNode(src.value), true)
13151316
end

script/vm/node.lua

+27
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ function mt:remove(name)
227227
or (c.type == 'doc.type.boolean' and name == 'false' and c[1] == false)
228228
or (c.type == 'doc.type.table' and name == 'table')
229229
or (c.type == 'doc.type.array' and name == 'table')
230+
or (c.type == 'doc.type.sign' and name == 'table')
230231
or (c.type == 'doc.type.function' and name == 'function') then
231232
table.remove(self, index)
232233
self[c] = nil
@@ -247,6 +248,7 @@ function mt:narrow(name)
247248
or (c.type == 'doc.type.boolean' and name == 'boolean')
248249
or (c.type == 'doc.type.table' and name == 'table')
249250
or (c.type == 'doc.type.array' and name == 'table')
251+
or (c.type == 'doc.type.sign' and name == 'table')
250252
or (c.type == 'doc.type.function' and name == 'function') then
251253
goto CONTINUE
252254
end
@@ -328,6 +330,31 @@ function mt:hasName(name)
328330
return false
329331
end
330332

333+
---@return vm.node
334+
function mt:asTable()
335+
self.optional = nil
336+
for index = #self, 1, -1 do
337+
local c = self[index]
338+
if c.type == 'table'
339+
or c.type == 'doc.type.table'
340+
or c.type == 'doc.type.array'
341+
or c.type == 'doc.type.sign' then
342+
goto CONTINUE
343+
end
344+
if c.type == 'global' and c.cate == 'type' then
345+
---@cast c vm.global
346+
if c.name == 'table'
347+
or not guide.isBasicType(c.name) then
348+
goto CONTINUE
349+
end
350+
end
351+
table.remove(self, index)
352+
self[c] = nil
353+
::CONTINUE::
354+
end
355+
return self
356+
end
357+
331358
---@return fun():vm.node.object
332359
function mt:eachObject()
333360
local i = 0

test/type_inference/init.lua

+7
Original file line numberDiff line numberDiff line change
@@ -3350,3 +3350,10 @@ local s
33503350
local test = t[n]
33513351
local <?test2?> = t[s] --test and test2 are unknow
33523352
]]
3353+
3354+
TEST 'table<number, boolean>' [[
3355+
---@type table<number, boolean>
3356+
local t
3357+
3358+
<?t?> = {}
3359+
]]

0 commit comments

Comments
 (0)