From f86c80cf43729d09f816c2ae7c13a26d80ed1179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 18 Jun 2022 16:54:50 +0800 Subject: update --- script/vm/type.lua | 10 +++++----- test/diagnostics/type-check.lua | 11 +++++++++++ test/full/example.lua | 1 + test/full/init.lua | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/script/vm/type.lua b/script/vm/type.lua index d2c5d663..15c94dfc 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -1,5 +1,6 @@ ---@class vm local vm = require 'vm.vm' +local guide = require 'parser.guide' ---@param object vm.object ---@return string? @@ -50,11 +51,6 @@ function vm.isSubType(uri, child, parent, mark) return false end end - if child:isOptional() then - if not vm.isSubType(uri, 'nil', parent, mark) then - return false - end - end return true end @@ -93,6 +89,10 @@ function vm.isSubType(uri, child, parent, mark) return true end + if parentName == 'table' and not guide.isBasicType(childName) then + return true + end + -- check class parent if not mark[child] then mark[child] = true diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 9de3e061..c8ea17a4 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -159,6 +159,17 @@ local x = 0 = 1.0 ]] +TEST [[ +---@class A + +local t = {} + +---@type A +local a + +t = a +]] + do return end TEST [[ ---@diagnostic disable: unused-local diff --git a/test/full/example.lua b/test/full/example.lua index 6afbf2d6..7740d23c 100644 --- a/test/full/example.lua +++ b/test/full/example.lua @@ -22,6 +22,7 @@ local function testIfExit(path) local noderClock = 0 local total for i = 1, max do + ---@type table state = TEST(buf) local luadocStart = os.clock() luadoc(state) diff --git a/test/full/init.lua b/test/full/init.lua index 3b1d2fe2..ac78f134 100644 --- a/test/full/init.lua +++ b/test/full/init.lua @@ -6,7 +6,7 @@ rawset(_G, 'TEST', true) function TEST(script) local clock = os.clock() - local state = parser.compile(script, 'Lua', 'Lua 5.3') + local state = parser.compile(script, 'Lua', 'Lua 5.4') state.compileClock = os.clock() - clock return state end -- cgit v1.2.3