diff options
author | sumneko <sumneko@hotmail.com> | 2022-03-11 02:54:36 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-03-11 02:54:36 +0800 |
commit | bb02090e9f63355cda301a66571da9d2cd141334 (patch) | |
tree | 0baa80f28f442bee7e474c69e3c063f3dec276f6 | |
parent | c979f901d19440c6f2cdc899ea38e7c9dc204405 (diff) | |
download | lua-language-server-bb02090e9f63355cda301a66571da9d2cd141334.zip |
update
-rw-r--r-- | script/vm/compiler.lua | 10 | ||||
-rw-r--r-- | script/vm/infer.lua | 4 | ||||
-rw-r--r-- | script/vm/sign.lua | 7 | ||||
-rw-r--r-- | test/type_inference/init.lua | 29 |
4 files changed, 41 insertions, 9 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index da38c334..eda85f83 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -165,9 +165,9 @@ local function getObjectSign(source) if not source._sign then return false end - for _, doc in ipairs(source.bindDocs) do - if doc.type == 'doc.param' then - source._sign:addSign(doc.extends) + if source.args then + for _, arg in ipairs(source.args) do + source._sign:addSign(m.compileNode(arg)) end end end @@ -183,7 +183,7 @@ local function getObjectSign(source) source._sign = signMgr() if source.type == 'doc.type.function' then for _, arg in ipairs(source.args) do - source._sign:addSign(arg.extends) + source._sign:addSign(m.compileNode(arg.extends)) end end end @@ -262,7 +262,7 @@ local function getReturn(func, index, args) if returnNode and returnNode.type == 'generic' then returnNode = returnNode:resolve(args) end - if returnNode then + if returnNode and returnNode.type ~= 'doc.generic.name' then result = result or union() result:merge(m.compileNode(returnNode)) end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index f393306c..47553517 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -60,6 +60,10 @@ local viewNodeMap = util.switch() return source[1] end end) + : case 'doc.generic.name' + : call(function (source, options) + return ('<%s>'):format(source[1]) + end) : case 'doc.type.array' : call(function (source, options) options['hasClass'] = true diff --git a/script/vm/sign.lua b/script/vm/sign.lua index aa1cf110..74b59347 100644 --- a/script/vm/sign.lua +++ b/script/vm/sign.lua @@ -8,10 +8,9 @@ local mt = {} mt.__index = mt mt.type = 'sign' ----@param key parser.object -function mt:addSign(key) - local compiler = require 'vm.compiler' - self.signList[#self.signList+1] = compiler.compileNode(key) +---@param node vm.node +function mt:addSign(node) + self.signList[#self.signList+1] = node end ---@param argNodes vm.node[] diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 188ca06b..7721e776 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -656,6 +656,35 @@ local t local <?k?>, v = f2(t) ]] +TEST 'fun(a: <V>):integer, <V>' [[ +---@generic K, V +---@param a K +---@return fun(a: V):K, V +local function f(a) end + +local <?f2?> = f(1) +]] + +TEST 'integer' [[ +---@generic K, V +---@param a K +---@return fun(a: V):K, V +local function f(a) end + +local f2 = f(1) +local <?i?>, v = f2(true) +]] + +TEST 'boolean' [[ +---@generic K, V +---@param a K +---@return fun(a: V):K, V +local function f(a) end + +local f2 = f(1) +local i, <?v?> = f2(true) +]] + TEST 'string' [[ ---@class string |