diff options
-rw-r--r-- | script/await.lua | 3 | ||||
-rw-r--r-- | script/parser/compile.lua | 2 | ||||
-rw-r--r-- | script/parser/guide.lua | 32 | ||||
-rw-r--r-- | 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 _, <?v?> 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 <?self?> +end +]] |