diff options
-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) ]] |