diff options
author | sumneko <sumneko@hotmail.com> | 2022-03-12 01:18:32 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-03-12 01:18:32 +0800 |
commit | 7baee6a3d54dc7cb94fb9db95d01244a17f126f6 (patch) | |
tree | 5115bddc691e44805b83700deb9325b8ee0dc85d | |
parent | e8e0f4d2db165be2d0df5ea9f3e2eb0bbc9df793 (diff) | |
download | lua-language-server-7baee6a3d54dc7cb94fb9db95d01244a17f126f6.zip |
update
-rw-r--r-- | script/vm/compiler.lua | 28 | ||||
-rw-r--r-- | test/type_inference/init.lua | 4 |
2 files changed, 29 insertions, 3 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 7d622f37..4427a66c 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -237,7 +237,14 @@ local function getReturnOfSetMetaTable(args) end if mt then m.compileByParentNode(mt, '__index', function (src) - node:merge(m.compileNode(src)) + for n in nodeMgr.eachNode(m.compileNode(src)) do + if n.type == 'global' + or n.type == 'local' + or n.type == 'table' + or n.type == 'doc.type.table' then + node:merge(n) + end + end end) end return node @@ -426,6 +433,7 @@ local compilerMap = util.switch() end end + -- table.sort(string[], function (<?x?>) end) if source.parent.type == 'callargs' then local call = source.parent.parent local callNode = m.compileNode(call.node) @@ -442,6 +450,24 @@ local compilerMap = util.switch() end end end + if call.node.special == 'pcall' + or call.node.special == 'xpcall' then + local fixIndex = call.node.special == 'pcall' and 1 or 2 + callNode = m.compileNode(call.args[1]) + for n in nodeMgr.eachNode(callNode) do + if n.type == 'function' then + for index, arg in ipairs(n.args) do + if call.args[index + fixIndex] == source then + for fn in nodeMgr.eachNode(m.compileNode(arg)) do + if fn.type == 'doc.type.function' then + nodeMgr.setNode(source, fn) + end + end + end + end + end + end + end end end) : case 'paren' diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 223b2e44..e253cba5 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -1085,14 +1085,14 @@ work(function (<?value?>) end) ]] -TEST 'Class' [[ +TEST 'fun(value: Class)' [[ ---@class Class ---@param callback fun(value: Class) function work(callback) end -pcall(work, function (<?value?>) +pcall(work, <?function?> (value) end) ]] |