From 0dae347da5874b59db867a9d318593f8534ab03b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 1 Mar 2021 18:16:12 +0800 Subject: kick class extends --- script/await.lua | 3 +++ script/parser/compile.lua | 2 +- script/parser/guide.lua | 32 +++++++++++++++++++++++++++++++- test/type_inference/init.lua | 13 +++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/script/await.lua b/script/await.lua index eb74fca6..6815bc1a 100644 --- a/script/await.lua +++ b/script/await.lua @@ -69,6 +69,9 @@ end --- 设置一个id,用于批量关闭任务 function m.setID(id, co) co = co or coroutine.running() + if not coroutine.isyieldable(co) then + return + end if not m.idMap[id] then m.idMap[id] = setmetatable({}, { __mode = 'k' }) end diff --git a/script/parser/compile.lua b/script/parser/compile.lua index 3c15beac..d55dc395 100644 --- a/script/parser/compile.lua +++ b/script/parser/compile.lua @@ -540,7 +540,7 @@ return function (self, lua, mode, version, options) if not state then return nil, err end - if options.delay then + if options and options.delay then options.delay() end local clock = os.clock() diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 4673b475..1c410453 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -3198,6 +3198,20 @@ function m.mergeTypes(types) return tableConcat(results, '|') end +function m.getClassExtends(class) + if class.type == 'doc.class.name' then + class = class.parent + end + if not class.extends then + return nil + end + local names = {} + for _, ext in ipairs(class.extends) do + names[#names+1] = ext[1] + end + return names +end + function m.viewInferType(infers) if not infers then return 'any' @@ -3237,10 +3251,26 @@ function m.viewInferType(infers) if hasDocTable and tp == 'table' then goto CONTINUE end - types[tp] = true + if types[tp] == nil then + types[tp] = true + end + end + if src.type == 'doc.class' + or src.type == 'doc.class.name' then + local extends = m.getClassExtends(src) + if extends then + for _, tp in ipairs(extends) do + types[tp] = false + end + end end ::CONTINUE:: end + for k, v in pairs(types) do + if not v then + types[k] = nil + end + end else for i = 1, #infers do local infer = infers[i] diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index c211283a..578e75d4 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -562,3 +562,16 @@ local t for _, in ipairs(t) do end ]] + +TEST 'E' [[ +---@class A +---@class B: A +---@class C: B +---@class D: C +---@class E: D +local m + +function m:f() + return +end +]] -- cgit v1.2.3