diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-11-05 22:19:21 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-11-05 22:19:21 +0800 |
commit | 385235cd95b8a23356c8947912c9426cef37c61f (patch) | |
tree | 139a586389d29de8a8fdf7b4b35d3779609bfc21 /script/vm | |
parent | b870bc090ce17747de961a713fc6333d2e6d401f (diff) | |
download | lua-language-server-385235cd95b8a23356c8947912c9426cef37c61f.zip |
check parameter types of generic extends
resolve #1663
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/infer.lua | 8 | ||||
-rw-r--r-- | script/vm/sign.lua | 18 | ||||
-rw-r--r-- | script/vm/type.lua | 14 |
3 files changed, 25 insertions, 15 deletions
diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 26cfdf44..066f72e6 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -107,8 +107,12 @@ local viewNodeSwitch;viewNodeSwitch = util.switch() return vm.getInfer(source.proto):view(uri) end) : case 'doc.generic.name' - : call(function (source, infer) - return ('<%s>'):format(source[1]) + : call(function (source, infer, uri) + if source.generic and source.generic.extends then + return ('<%s:%s>'):format(source[1], vm.getInfer(source.generic.extends):view(uri)) + else + return ('<%s>'):format(source[1]) + end end) : case 'doc.type.array' : call(function (source, infer, uri) diff --git a/script/vm/sign.lua b/script/vm/sign.lua index 3791ca4f..3fc9f981 100644 --- a/script/vm/sign.lua +++ b/script/vm/sign.lua @@ -3,8 +3,9 @@ local guide = require 'parser.guide' local vm = require 'vm.vm' ---@class vm.sign ----@field parent parser.object ----@field signList vm.node[] +---@field parent parser.object +---@field signList vm.node[] +---@field docGenric parser.object[] local mt = {} mt.__index = mt mt.type = 'sign' @@ -14,11 +15,15 @@ function mt:addSign(node) self.signList[#self.signList+1] = node end +---@param doc parser.object +function mt:addDocGeneric(doc) + self.docGenric[#self.docGenric+1] = doc +end + ---@param uri uri ---@param args parser.object ----@param removeGeneric true? ---@return table<string, vm.node>? -function mt:resolve(uri, args, removeGeneric) +function mt:resolve(uri, args) if not args then return nil end @@ -256,7 +261,8 @@ end ---@return vm.sign function vm.createSign() local genericMgr = setmetatable({ - signList = {}, + signList = {}, + docGenric = {}, }, mt) return genericMgr end @@ -285,8 +291,8 @@ function vm.getSign(source) if doc.type == 'doc.generic' then if not source._sign then source._sign = vm.createSign() - break end + source._sign:addDocGeneric(doc) end end if not source._sign then diff --git a/script/vm/type.lua b/script/vm/type.lua index 53b1ec3b..410ece8c 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -169,13 +169,13 @@ function vm.isSubType(uri, child, parent, mark) end parent = global elseif parent.type == 'vm.node' then + local hasKnownType for n in parent:eachObject() do - if getNodeName(n) - and vm.isSubType(uri, child, n, mark) == true then - return true - end - if n.type == 'doc.generic.name' then - return true + if getNodeName(n) then + hasKnownType = true + if vm.isSubType(uri, child, n, mark) == true then + return true + end end end if parent:isOptional() then @@ -183,7 +183,7 @@ function vm.isSubType(uri, child, parent, mark) return true end end - return false + return not hasKnownType end ---@cast parent vm.node.object |