diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-10-23 19:13:58 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-10-23 19:13:58 +0800 |
commit | 2873ccae1dfb1d429a84262f10c87f1d437135c6 (patch) | |
tree | 3a444805d35e7a634a8e0a026b07bbb96caa3660 /script/vm/compiler.lua | |
parent | 96b320247788163f7d014404b7b1f089aed82dff (diff) | |
download | lua-language-server-2873ccae1dfb1d429a84262f10c87f1d437135c6.zip |
infer parameter type by return
resolve #1202
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r-- | script/vm/compiler.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index ad1379fc..599b2c4a 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1059,6 +1059,7 @@ local function compileLocal(source) end if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then local func = source.parent.parent + -- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number local funcNode = vm.compileNode(func) local hasDocArg for n in funcNode:eachObject() do @@ -1158,6 +1159,22 @@ local compilerSwitch = util.switch() local call = source.parent.parent vm.compileCallArg(source, call) end + + -- function f() return function (<?x?>) end end + if source.parent.type == 'return' then + for i, ret in ipairs(source.parent) do + if ret == source then + local func = guide.getParentFunction(source.parent) + if func then + local returnObj = vm.getReturnOfFunction(func, i) + if returnObj then + vm.setNode(source, vm.compileNode(returnObj)) + end + end + break + end + end + end end) : case 'paren' : call(function (source) |