diff options
author | sumneko <sumneko@hotmail.com> | 2022-03-11 23:26:01 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-03-11 23:26:01 +0800 |
commit | 18ef2f600c3f389e6984e2366e8b0c93d30d5792 (patch) | |
tree | 14e7139cc38a08e4e100fdf48cd1fd754ae3233c | |
parent | 0cd41e39f4439a442ef8d7b55e79549f48591034 (diff) | |
download | lua-language-server-18ef2f600c3f389e6984e2366e8b0c93d30d5792.zip |
update
-rw-r--r-- | script/vm/node.lua | 3 | ||||
-rw-r--r-- | script/vm/type.lua | 34 |
2 files changed, 33 insertions, 4 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index 082a5e87..b8b7917d 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -16,6 +16,9 @@ function m.mergeNode(a, b) if not b then return a end + if not a then + return b + end if a.type == 'union' then a:merge(b) return a diff --git a/script/vm/type.lua b/script/vm/type.lua index 5bdc975b..8b80d4f3 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -78,13 +78,26 @@ function m.getTableValue(tnode, knode) if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do if m.isSubType(field.name, knode) then - result = nodeMgr.mergeNode(compiler.compileNode(field.extends), result) + result = nodeMgr.mergeNode(result, compiler.compileNode(field.extends)) end end end if tn.type == 'doc.type.array' then if m.isSubType(globalMgr.getGlobal('type', 'integer'), knode) then - result = nodeMgr.mergeNode(compiler.compileNode(tn.node), result) + result = nodeMgr.mergeNode(result, compiler.compileNode(tn.node)) + end + end + if tn.type == 'table' then + for _, field in ipairs(tn) do + if field.type == 'tableindex' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.value)) + end + if field.type == 'tablefield' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.value)) + end + if field.type == 'tableexp' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.value)) + end end end end @@ -99,13 +112,26 @@ function m.getTableKey(tnode, vnode) if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do if m.isSubType(field.extends, vnode) then - result = nodeMgr.mergeNode(compiler.compileNode(field.name), result) + result = nodeMgr.mergeNode(result, compiler.compileNode(field.name)) end end end if tn.type == 'doc.type.array' then if m.isSubType(tn.node, vnode) then - result = nodeMgr.mergeNode(globalMgr.getGlobal('type', 'integer'), result) + result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'integer')) + end + end + if tn.type == 'table' then + for _, field in ipairs(tn) do + if field.type == 'tableindex' then + result = nodeMgr.mergeNode(result, compiler.compileNode(field.index)) + end + if field.type == 'tablefield' then + result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'string')) + end + if field.type == 'tableexp' then + result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'integer')) + end end end end |