diff options
-rw-r--r-- | script/parser/guide.lua | 23 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 16 |
2 files changed, 38 insertions, 1 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index a6b11744..2932f159 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1478,6 +1478,27 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, queue) end end +local function toValidGenericType(status, obj) + if obj.type ~= 'string' then + return obj + end + + if not status.interface.docType then + return obj + end + + local docs = status.interface.docType(obj[1]) + for i = 1, #docs do + local doc = docs[i] + if doc.type == 'doc.class.name' + or doc.type == 'doc.alias.name' then + return doc + end + end + + return obj +end + local function stepRefOfGeneric(status, typeUnit, args, mode) if not args then return nil @@ -1502,7 +1523,7 @@ local function stepRefOfGeneric(status, typeUnit, args, mode) and source.parent.type == 'funcargs' then for index, arg in ipairs(source.parent) do if arg == source then - results[#results+1] = args[index] + results[#results+1] = toValidGenericType(status, args[index]) end end end diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index cfd0f4cb..5fdc3891 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -945,3 +945,19 @@ v2 = v v2:method1() v2:method2() -- 这个感觉实际应该报错更合适 ]] + +TEST [[ +---@generic T +---@param arg1 T +---@return T +function Generic(arg1) return arg1 end + +---@class Foo +---@field bar1 integer +local Foo = {} + +local v1 = Generic("Foo") +print(v1.bar1) +local v2 = Generic(Foo) +print(v2.bar1) +]] |