summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/infer.lua4
-rw-r--r--test/type_inference/init.lua7
3 files changed, 11 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index 76524c59..0a98c3ec 100644
--- a/changelog.md
+++ b/changelog.md
@@ -19,6 +19,7 @@
* `CHG` improve hover color
* `CHG` improve performance
* `FIX` supports for file with LF
+* `FIX` may infer a custom class as a string
## 2.1.0
`2021-7-2`
diff --git a/script/core/infer.lua b/script/core/infer.lua
index aa1e1f28..c4af5122 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -244,7 +244,9 @@ local function cleanInfers(infers)
-- 如果是通过 # 来推测的,且结果里没有其他的 table 与 string,则加入这2个类型
if infers[STRING_OR_TABLE] then
infers[STRING_OR_TABLE] = nil
- if not infers['table'] and not infers['string'] then
+ if not infers['table']
+ and not infers['string']
+ and not infers[CLASS] then
infers['table'] = true
infers['string'] = true
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index c07074f7..77440cf6 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -882,3 +882,10 @@ print(t.<?x?>)
TEST 'table' [[
local <?t?> = setmetatable({}, { __index = function () end })
]]
+
+TEST 'player' [[
+---@class player
+local t
+
+<?t?>:getOwner()
+]]