diff options
-rw-r--r-- | script/vm/compiler.lua | 13 | ||||
-rw-r--r-- | test/hover/init.lua | 12 | ||||
-rw-r--r-- | test/type_inference/init.lua | 15 |
3 files changed, 38 insertions, 2 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index c92c224a..19955372 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -20,19 +20,28 @@ local m = {} local searchFieldSwitch = util.switch() : case 'table' : call(function (node, key, pushResult) + local tp + if type(key) == 'table' + and key.type == 'global' + and key.cate == 'type' then + tp = key.name + end local hasFiled = false for _, field in ipairs(node) do if field.type == 'tablefield' or field.type == 'tableindex' then + local fieldKey = guide.getKeyName(field) if key == nil - or key == guide.getKeyName(field) then + or key == fieldKey + or (tp == 'integer' and math.tointeger(fieldKey)) then hasFiled = true pushResult(field) end end if field.type == 'tableexp' then if key == nil - or key == field.tindex then + or key == field.tindex + or tp == 'integer' then hasFiled = true pushResult(field) end diff --git a/test/hover/init.lua b/test/hover/init.lua index 2ae6837f..4337c4a4 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1816,3 +1816,15 @@ local <?x?> = '1' .. '2' [[ local x: string = "12" ]] + +TEST [[ +local t = { + x = 1, + [1] = 'x', +} + +local <?x?> = t[#t] +]] +[[ +local x: string = "x" +]] diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index bad1a876..4d1cfb4a 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -1419,3 +1419,18 @@ local t = { local <?x?> = t[#t] ]] + +TEST 'string' [[ +local t = { + x = 1, + [1] = 'x', +} + +local <?x?> = t[#t] +]] + +TEST 'string' [[ +local t = { 'x' } + +local <?x?> = t[#t] +]] |