summaryrefslogtreecommitdiff
path: root/test/diagnostics/cast-local-type.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-08-15 15:20:52 +0800
committerGitHub <noreply@github.com>2024-08-15 15:20:52 +0800
commit7c9a24fc2e80952e5045a2855f37b997ab93ee80 (patch)
treeaa192cf6d6ed02d02dda8c8b7a4c240dded64efb /test/diagnostics/cast-local-type.lua
parentb71cb7aecd9337c9463a4dfbdb9d06cac7b825fd (diff)
parent2c798703ca854d670fb28f51adc85c2b41f08f37 (diff)
downloadlua-language-server-7c9a24fc2e80952e5045a2855f37b997ab93ee80.zip
Merge pull request #2768 from NeOzay/cast-table-to-class
check that the shape of the table corresponds to the class
Diffstat (limited to 'test/diagnostics/cast-local-type.lua')
-rw-r--r--test/diagnostics/cast-local-type.lua66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/diagnostics/cast-local-type.lua b/test/diagnostics/cast-local-type.lua
index f79bf48d..93452a92 100644
--- a/test/diagnostics/cast-local-type.lua
+++ b/test/diagnostics/cast-local-type.lua
@@ -332,3 +332,69 @@ local x
- 类型 `nil` 无法匹配 `'B'`
- 类型 `nil` 无法匹配 `'A'`]])
end)
+
+TEST [[
+---@class A
+---@field x string
+---@field y number
+
+local a = {x = "", y = 0}
+
+---@type A
+local v
+v = a
+]]
+
+TEST [[
+---@class A
+---@field x string
+---@field y number
+
+local a = {x = ""}
+
+---@type A
+local v
+<!v!> = a
+]]
+
+TEST [[
+---@class A
+---@field x string
+---@field y number
+
+local a = {x = "", y = ""}
+
+---@type A
+local v
+<!v!> = a
+]]
+
+TEST [[
+---@class A
+---@field x string
+---@field y? B
+
+---@class B
+---@field x string
+
+local a = {x = "b", y = {x = "c"}}
+
+---@type A
+local v
+v = a
+]]
+
+TEST [[
+---@class A
+---@field x string
+---@field y B
+
+---@class B
+---@field x string
+
+local a = {x = "b", y = {}}
+
+---@type A
+local v
+<!v!> = a
+]]