From 2da06eec62bb54118cab8276fdc9ce09928482c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 13 Nov 2024 15:25:01 +0800 Subject: [PATCH] `FIX` Incorrect type check in some case --- changelog.md | 4 ++++ script/vm/type.lua | 2 ++ test/diagnostics/param-type-mismatch.lua | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/changelog.md b/changelog.md index 500b2a523..7879b71d7 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,10 @@ ## Unreleased +## 3.13.1 +`2024-11-13` +* `FIX` Incorrect type check in some case + ## 3.13.0 `2024-11-13` * `NEW` Setting: `Lua.type.inferTableSize`: A Small Table array can be infered diff --git a/script/vm/type.lua b/script/vm/type.lua index 4e6394f31..de53c941b 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -587,8 +587,10 @@ function vm.isSubType(uri, child, parent, mark, errs) and not mark[childName] then mark[childName] = true if vm.isSubType(uri, parentName, childName, mark) then + mark[childName] = nil return true end + mark[childName] = nil end if errs then diff --git a/test/diagnostics/param-type-mismatch.lua b/test/diagnostics/param-type-mismatch.lua index b385d8a8c..c67d42b0b 100644 --- a/test/diagnostics/param-type-mismatch.lua +++ b/test/diagnostics/param-type-mismatch.lua @@ -364,4 +364,24 @@ local i f(i) ]] +TEST [[ +---@class A: integer + +---@param a A +local function f(a) end + +local t = { + { int = 123 }, + { int = 456 }, + { int = 789 }, +} + +---@type integer +local i + +local k = t[i].int + +f(k) +]] + config.set(nil, 'Lua.type.checkTableShape', false)